Skip to content
Prev Previous commit
Next Next commit
Iteration #2: Find longest word
  • Loading branch information
ericksicard committed Oct 29, 2019
commit 45c8ded51592e32f8e93db02665522b3d2a7426a
10 changes: 10 additions & 0 deletions starter-code/src/functions-and-arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ function maxOfTwoNumbers(num1, num2) {

// Iteration #2: Find longest word
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
function findLongestWord(arr) {

//Simple local comprobation
console.log(arr.map( elm => ({[elm]: elm.length}) ))

let result = arr.
reduce( (acc, cur) => acc.length >= cur.length ? acc : acc = cur);

return result;
}

// Iteration #3: Calculate the sum

Expand Down