Skip to content

Commit b135099

Browse files
committed
Iteration ironhack-labs#2: Find longest word
1 parent 802a94e commit b135099

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/functions-and-arrays.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ function maxOfTwoNumbers(number1, number2) {
1212
}
1313

1414

15-
1615
// Iteration #2: Find longest word
1716
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
1817

1918
function findLongestWord(arr) {
20-
if(!arr) return;
21-
let lengths = words.map(word => word.length);
22-
return Math.max(...lengths);
23-
}
24-
findLongestWord(words);
19+
let longest = arr[0];
20+
for (let i = 0; i < arr.length; i++) {
21+
if (arr[i].length > longest.length) return longest = arr[i];
22+
return;
23+
}
24+
25+
findLongestWord(words);
2526

2627

2728
// Iteration #3: Calculate the sum
@@ -119,8 +120,10 @@ function uniquifyArray(arr) {
119120
// Iteration #6: Find elements
120121
const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience'];
121122

122-
function doesWordExist() {}
123+
function doesWordExist(arr, searchfor) {
123124

125+
}
126+
doesWordExist(wordsFind, search);
124127

125128

126129
// Iteration #7: Count repetition

0 commit comments

Comments
 (0)