-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Ber wd pt Camille - complete #1472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,63 @@ | ||
// Iteration #1: Find the maximum | ||
|
||
function maxOfTwoNumbers (num1, num2){ | ||
console.log(Math.max(num1, num2)) | ||
} | ||
|
||
maxOfTwoNumbers(4, 7) | ||
|
||
// Iteration #2: Find longest word | ||
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot']; | ||
|
||
function findLongestWord(myWords){ | ||
let longestWord = 0 | ||
|
||
for (let i = 0; i < myWords.length; i++){ | ||
if (myWords[i].length > longestWord){ | ||
longestWord = myWords[i] | ||
} | ||
return longestWord | ||
//console.log(i) | ||
//console.log(longestWord) | ||
} | ||
} | ||
|
||
findLongestWord(words) | ||
|
||
// Iteration #3: Calculate the sum | ||
|
||
const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; | ||
|
||
let result3 = 0 | ||
|
||
function sumArray(myNumber){ | ||
for (let i=0; i < myNumber.length; i++){ | ||
result3 += myNumber[i] | ||
} | ||
return result3 | ||
} | ||
sumArray(numbers) | ||
//console.log(result) | ||
|
||
// Iteration #4: Calculate the average | ||
// Level 1: Array of numbers | ||
const numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9]; | ||
|
||
|
||
const numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9]; | ||
|
||
let result4a = 0 | ||
|
||
function averageNumbers(myNumbersAvg){ | ||
for (let i=0; i < myNumbersAvg.length; i++){ | ||
result4a += myNumbersAvg[i] / myNumbersAvg.length | ||
} | ||
return result4a | ||
} | ||
averageNumbers(numbersAvg) | ||
|
||
// Level 2: Array of strings | ||
|
||
const wordsArr = [ | ||
'seat', | ||
'correspond', | ||
|
@@ -25,6 +71,28 @@ const wordsArr = [ | |
'palace' | ||
]; | ||
|
||
let result4b = 0 | ||
let countLetters = [] | ||
|
||
function numberOfLetters(myWordsArr){ | ||
for (let i=0; i < myWordsArr.length; i++){ | ||
countLetters.push(myWordsArr[i].length) | ||
} | ||
return countLetters | ||
} | ||
|
||
numberOfLetters(wordsArr) | ||
|
||
|
||
function averageWordLength(myCountLetters){ | ||
for (let i=0; i < myCountLetters.length; i++){ | ||
result4b += myCountLetters[i] / myCountLetters.length | ||
} | ||
return Math.floor(result4b) | ||
} | ||
averageWordLength(countLetters) | ||
|
||
|
||
// Iteration #5: Unique arrays | ||
const wordsUnique = [ | ||
'crab', | ||
|
@@ -40,6 +108,29 @@ const wordsUnique = [ | |
'bring' | ||
]; | ||
|
||
|
||
let result=[] | ||
|
||
function check(array) { | ||
for (let i=0; i < array.length; i++){ | ||
if (array.indexOf(array[i]) !== i){ | ||
result.push(array[i]) | ||
} | ||
} | ||
} | ||
check(words) | ||
|
||
function list(array) { | ||
for (let i=0; i < array.length; i++){ | ||
console.log(array.indexOf(array[i])) | ||
} | ||
} | ||
list(words) | ||
|
||
console.log(result) | ||
|
||
|
||
|
||
// Iteration #6: Find elements | ||
const wordsFind = [ | ||
'machine', | ||
|
@@ -52,6 +143,19 @@ const wordsFind = [ | |
'disobedience' | ||
]; | ||
|
||
|
||
function doesWordExist(array, check){ | ||
for(let i=0; i < array.length; i++){ | ||
if(check === array[i]){ | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
doesWordExist(words2, "hello") | ||
|
||
|
||
// Iteration #7: Count repetition | ||
const wordsCount = [ | ||
'machine', | ||
|
@@ -67,6 +171,18 @@ const wordsCount = [ | |
'matter' | ||
]; | ||
|
||
let numberofTimes = 0 | ||
|
||
function howManyTimes(array, check){ | ||
for(let i=0; i < array.length; i++){ | ||
if(check === array[i]){ | ||
numberofTimes++; | ||
} | ||
} | ||
} | ||
|
||
howManyTimes(words3, "matter") | ||
console.log(numberofTimes) | ||
// Iteration #8: Bonus | ||
|
||
const matrix = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. really good nice job |
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice job, also i could say as you see we have sumArray function and we could use it to get the average but its really good nice