-
Notifications
You must be signed in to change notification settings - Fork 6.7k
[FTRMT052023] - Maria Friedemann #3815
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,20 +1,54 @@ | ||||||||||
// Iteration #1: Find the maximum | ||||||||||
function maxOfTwoNumbers() {} | ||||||||||
|
||||||||||
function maxOfTwoNumbers(a, b) { | ||||||||||
if (a>b) { | ||||||||||
return a; | ||||||||||
} else if (a<b) { | ||||||||||
return b; | ||||||||||
} else { | ||||||||||
return a, b; | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
|
||||||||||
// Iteration #2: Find longest word | ||||||||||
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot']; | ||||||||||
|
||||||||||
function findLongestWord() {} | ||||||||||
|
||||||||||
function findLongestWord(array) { | ||||||||||
if (array.length === 0) { | ||||||||||
return null; | ||||||||||
} | ||||||||||
let longestWord = ''; | ||||||||||
for (let i = 0; i < array.length; i++) { | ||||||||||
|
||||||||||
if (array[i].length > longestWord.length) { | ||||||||||
longestWord = array[i]; | ||||||||||
} | ||||||||||
} | ||||||||||
return longestWord; | ||||||||||
} | ||||||||||
|
||||||||||
|
||||||||||
// Iteration #3: Calculate the sum | ||||||||||
const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; | ||||||||||
|
||||||||||
function sumNumbers() {} | ||||||||||
function sumNumbers(array) { | ||||||||||
if (array.length === 0) { | ||||||||||
return 0; | ||||||||||
} | ||||||||||
let sumOfNumbers = 0; | ||||||||||
for (let i= 0; i < array.length; i++) { | ||||||||||
|
||||||||||
sumOfNumbers += array[i]; | ||||||||||
|
||||||||||
if (array[i] === 0) { | ||||||||||
return 0; | ||||||||||
} else { | ||||||||||
return sumOfNumbers; | ||||||||||
} | ||||||||||
|
||||||||||
} | ||||||||||
|
||||||||||
} | ||||||||||
|
||||||||||
|
||||||||||
// Iteration #3.1 Bonus: | ||||||||||
|
@@ -26,13 +60,36 @@ function sum() {} | |||||||||
// Level 1: Array of numbers | ||||||||||
const numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9]; | ||||||||||
|
||||||||||
function averageNumbers() {} | ||||||||||
function averageNumbers(array) { | ||||||||||
if (array.length === 0) { | ||||||||||
return null; | ||||||||||
} | ||||||||||
let sumOfNumbers = 0; | ||||||||||
for (let i= 0; i < array.length; i++) { | ||||||||||
|
||||||||||
sumOfNumbers += array[i]; | ||||||||||
} | ||||||||||
return sumOfNumbers / array.length; | ||||||||||
} | ||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
// Level 2: Array of strings | ||||||||||
const wordsArr = ['seat', 'correspond', 'linen', 'motif', 'hole', 'smell', 'smart', 'chaos', 'fuel', 'palace']; | ||||||||||
|
||||||||||
function averageWordLength() { } | ||||||||||
function averageWordLength(array) { | ||||||||||
if (array.length === 0) { | ||||||||||
return null; | ||||||||||
} | ||||||||||
let sumOfStrings = 0; | ||||||||||
for (let i = 0; i < array.length; i++) { | ||||||||||
sumOfStrings += array[i]; | ||||||||||
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. If you add that one you would get the tests passing, we want the average length of the word :)
Suggested change
|
||||||||||
} | ||||||||||
return sumOfStrings / array.length; | ||||||||||
} | ||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
// Bonus - Iteration #4.1 | ||||||||||
function avg() {} | ||||||||||
|
@@ -52,14 +109,24 @@ const wordsUnique = [ | |||||||||
'bring' | ||||||||||
]; | ||||||||||
|
||||||||||
function uniquifyArray() {} | ||||||||||
function uniquifyArray(array) { | ||||||||||
if (array.length === 0) { | ||||||||||
return null; | ||||||||||
} | ||||||||||
|
||||||||||
|
||||||||||
} | ||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
// Iteration #6: Find elements | ||||||||||
const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience']; | ||||||||||
|
||||||||||
function doesWordExist() {} | ||||||||||
function doesWordExist(array) { | ||||||||||
if (array.length === 0) { | ||||||||||
return null; | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
|
@@ -78,7 +145,23 @@ const wordsCount = [ | |||||||||
'matter' | ||||||||||
]; | ||||||||||
|
||||||||||
function howManyTimes() {} | ||||||||||
function howManyTimes(array) { | ||||||||||
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. Here you needed another parameter to pass what was searched
Suggested change
|
||||||||||
if (array.length === 0) { | ||||||||||
return 0; | ||||||||||
} | ||||||||||
let count = 0; | ||||||||||
|
||||||||||
for (let i = 0; i < array.length; i++) { | ||||||||||
for (let j = 0; j < array.length; j++) { | ||||||||||
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. and with the other parameter you won't need the second loop
Suggested change
|
||||||||||
if (array[i] === array[j]) { | ||||||||||
count++; | ||||||||||
break; | ||||||||||
} | ||||||||||
return count; | ||||||||||
} | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
|
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.
Here that return is inside the
for...loop
if you move it outside and remove theif...else
that function would work correctly