Skip to content

Commit c982bb4

Browse files
committed
Iteration ironhack-labs#5
1 parent 5ef0d62 commit c982bb4

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/functions-and-arrays.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function maxOfTwoNumbers(num1, num2) {
88
}
99
}
1010

11+
1112
// Iteration #2: Find longest word
1213
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
1314

@@ -28,6 +29,7 @@ function findLongestWord(anArr) {
2829
return longestWord
2930
}
3031

32+
3133
// Iteration #3: Calculate the sum
3234
const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];
3335

@@ -41,6 +43,7 @@ function sumNumbers(anArr) {
4143
return total
4244
}
4345

46+
4447
// Iteration #3.1 Bonus:
4548
function sum() {}
4649

@@ -62,6 +65,7 @@ function averageNumbers(anArr) {
6265
return average;
6366
}
6467

68+
6569
// Level 2: Array of strings
6670
const wordsArr = ['seat', 'correspond', 'linen', 'motif', 'hole', 'smell', 'smart', 'chaos', 'fuel', 'palace'];
6771

@@ -79,9 +83,11 @@ function averageWordLength(anArr) {
7983
return average
8084
}
8185

86+
8287
// Bonus - Iteration #4.1
8388
function avg() {}
8489

90+
8591
// Iteration #5: Unique arrays
8692
const wordsUnique = [
8793
'crab',
@@ -97,8 +103,18 @@ const wordsUnique = [
97103
'bring'
98104
];
99105

100-
function uniquifyArray() {}
101-
106+
function uniquifyArray(anArr) {
107+
if (anArr.length == 0)
108+
return null
109+
110+
let result = []
111+
for (let i = 0; i <anArr.length; i++){
112+
if (!result.includes(anArr[i])) {
113+
result.push(anArr[i])
114+
}
115+
}
116+
return result
117+
}
102118

103119

104120
// Iteration #6: Find elements

0 commit comments

Comments
 (0)