Skip to content

Commit 5ff86db

Browse files
committed
ironhack-labs#2 all tests are ok
1 parent 9b378b6 commit 5ff86db

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/functions-and-arrays.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ console.log(maxOfTwoNumbers(3, 3))
1414
// Iteration #2: Find longest word
1515
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
1616
//case Expected '' to be null. doesn't work
17-
function findLongestWord(array) {
17+
/* function findLongestWord(array) {
1818
let base = '';
1919
if (array !== []) {
2020
for (let i in array) {
@@ -27,6 +27,23 @@ function findLongestWord(array) {
2727
}
2828
return base;
2929
}
30+
console.log(findLongestWord(words))
31+
*/
32+
33+
34+
function findLongestWord(array) {
35+
36+
let base = null;
37+
if (array.length) {
38+
base = array[0];
39+
for (let i in array) {
40+
if (base.length < array[i].length) {
41+
base = array[i]
42+
}
43+
}
44+
}
45+
return base;
46+
}
3047
console.log(findLongestWord(words))
3148

3249
// Iteration #3: Calculate the sum

0 commit comments

Comments
 (0)