Skip to content

Commit 29fe530

Browse files
committed
interation ironhack-labs#2 e ironhack-labs#4 prontas
1 parent 24d5668 commit 29fe530

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/functions-and-arrays.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ function maxOfTwoNumbers(num1, num2){
1010

1111
// Iteration #2: Find longest word
1212
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
13-
function findLongestWord(wordArray) {
14-
13+
function findLongestWord(arr) {
14+
let longestWord = "";
15+
for (let i = 0;i < arr.length; i++){
16+
if (arr[i].length > longestWord.length){
17+
longestWord = arr[i]
18+
}
19+
}
20+
return longestWord
1521
}
1622

1723

18-
19-
2024
// Iteration #3: Calculate the sum
2125
const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];
2226

@@ -41,10 +45,17 @@ function sum() {}
4145
// Level 1: Array of numbers
4246
const numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9];
4347

44-
function averageNumbers() {}
48+
function averageNumbers(arr) {
49+
let avarege = 0
50+
for(let i = 0; i < arr.length; i++) {
51+
avarege += arr[i];
52+
}
53+
return (avarege / arr.length);
54+
}
55+
console.log(averageNumbers(numbersAvg))
4556

4657

47-
// Level 2: Array of strings
58+
// *Level 2: Array of strings
4859
const wordsArr = ['seat', 'correspond', 'linen', 'motif', 'hole', 'smell', 'smart', 'chaos', 'fuel', 'palace'];
4960

5061
function averageWordLength() { }

0 commit comments

Comments
 (0)