Skip to content

Commit 614fe0d

Browse files
committed
Iteration ironhack-labs#2: Find longest word - empty string
1 parent 45c8ded commit 614fe0d

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ function maxOfTwoNumbers(num1, num2) {
77
// Iteration #2: Find longest word
88
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
99
function findLongestWord(arr) {
10-
10+
1111
//Simple local comprobation
1212
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;
13+
14+
if ( arr.length > 0) {
15+
return arr.
16+
reduce( (acc, cur) => acc.length >= cur.length ? acc : acc = cur ,
17+
0);
18+
} else {
19+
return null;
20+
}
1821
}
1922

2023
// Iteration #3: Calculate the sum

0 commit comments

Comments
 (0)