Skip to content

Commit 2101b69

Browse files
author
Ivan Rubio
committed
Iteration ironhack-labs#2: Find longest word
1 parent eb19002 commit 2101b69

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/functions-and-arrays.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ function findLongestWord(array1) {
1919
} else if (array1.length === 1) {
2020
return array1[0]
2121
} else if (array1.length > 1) {
22-
let longest = " ";
22+
let longest = "";
2323

2424
array1.forEach(function(word) {
2525
if (word.length > longest.length) {
26-
word = longest;
26+
longest = word;
2727
}
28-
console.log(word);
2928
}
3029
);
30+
console.log(longest);
31+
return longest;
3132
}
3233
}
3334

0 commit comments

Comments
 (0)