Skip to content

Commit a8be51d

Browse files
committed
up until Iteration ironhack-labs#7
1 parent 313e472 commit a8be51d

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

src/functions-and-arrays.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,24 @@ const averageNumbers = (arrayNum) => {
7272
}
7373
}
7474

75-
console.log(averageNumbers(numbersAvg))
76-
7775
// Level 2: Array of strings
7876
const wordsArr = ['seat', 'correspond', 'linen', 'motif', 'hole', 'smell', 'smart', 'chaos', 'fuel', 'palace'];
7977

8078
const averageWordLength = (arratStr) => {
79+
const wordLengthArr = []
80+
for (i = 0; i < arratStr.length; i++) {
81+
wordLengthArr.push(arratStr[i].length)
82+
}
83+
return averageNumbers(wordLengthArr)
84+
};
8185

86+
87+
const avg = (arr) => {
88+
if (arr.length === 0) {
89+
return null
90+
} else {
91+
return Number((sum(arr) / arr.length).toFixed(2))
92+
}
8293
}
8394

8495
// Iteration #5: Unique arrays
@@ -96,9 +107,36 @@ const wordsUnique = [
96107
'bring'
97108
];
98109

110+
const uniquifyArray = (repeatedArray) => {
111+
if (repeatedArray.length === 0) {
112+
return null
113+
} else {
114+
const uniqueArray = []
115+
for (i = 0; i < repeatedArray.length; i++) {
116+
if (uniqueArray.indexOf(repeatedArray[i]) === -1) {
117+
uniqueArray.push(repeatedArray[i])
118+
}
119+
}
120+
return uniqueArray
121+
}
122+
}
123+
99124
// Iteration #6: Find elements
100125
const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience'];
101126

127+
const doesWordExist = (wordsArray, query) => {
128+
if (wordsArray.length === 0) {
129+
return null
130+
} else {
131+
for (i = 0; i < wordsArray.length; i++) {
132+
if (wordsArray[i] === query) {
133+
return true
134+
}
135+
}
136+
return false
137+
}
138+
}
139+
102140
// Iteration #7: Count repetition
103141
const wordsCount = [
104142
'machine',

0 commit comments

Comments
 (0)