Skip to content

Commit 3d56ce4

Browse files
committed
done Iteration ironhack-labs#2
1 parent 1cd7ba5 commit 3d56ce4

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/functions-and-arrays.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,22 @@ function maxOfTwoNumbers(firstNumber, secondNumber) {
1212
// Iteration #2: Find longest word
1313
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
1414

15-
function findLongestWord() {}
16-
15+
function findLongestWord(array) {
16+
if (array.length === 0){
17+
return null
18+
} else if (array.length === 1) {
19+
return (array[0])
20+
} else if (array.length > 1) {
21+
let longestWord = array[0]
22+
for (let i = 0; i < array.length; i++){
23+
if (array[i].length > longestWord.length){
24+
longestWord = array[i]
25+
}
26+
//Antes iba aquí la linea 28 pero si la bajo itera todos los elementos y obtengo la última respuesta que necesito.
27+
}
28+
return longestWord
29+
}
30+
}
1731

1832

1933
// Iteration #3: Calculate the sum

0 commit comments

Comments
 (0)