Skip to content

Commit 7996e1d

Browse files
committed
Iteration #2 completed
1 parent c9d3b85 commit 7996e1d

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@ function maxOfTwoNumbers(a, b) {
66
// Iteration #2: Find longest word
77
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
88

9+
function findLongestWord(words) {
10+
11+
if (!words.length) {
12+
return null;
13+
}
14+
15+
let longestWordCharCount = words.reduce(function (acc, e) {
16+
return acc > e.length ? acc : e.length;
17+
}, 0)
18+
19+
return words.find(function (e) {
20+
return e.length === longestWordCharCount;
21+
});
22+
}
23+
24+
findLongestWord(words);
25+
926
// Iteration #3: Calculate the sum
1027

1128
const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];

0 commit comments

Comments
 (0)