Skip to content

Commit 45c8ded

Browse files
committed
Iteration ironhack-labs#2: Find longest word
1 parent 5a24fab commit 45c8ded

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

starter-code/src/functions-and-arrays.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ function maxOfTwoNumbers(num1, num2) {
66

77
// Iteration #2: Find longest word
88
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
9+
function findLongestWord(arr) {
10+
11+
//Simple local comprobation
12+
console.log(arr.map( elm => ({[elm]: elm.length}) ))
13+
14+
let result = arr.
15+
reduce( (acc, cur) => acc.length >= cur.length ? acc : acc = cur);
16+
17+
return result;
18+
}
919

1020
// Iteration #3: Calculate the sum
1121

0 commit comments

Comments
 (0)