Skip to content

Commit 9555b4b

Browse files
author
Chris Weber
committed
1 parent 00e5a75 commit 9555b4b

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/functions-and-arrays.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,20 @@ const wordsArr = [
9090
"palace",
9191
];
9292

93-
function averageWordLength() {}
93+
function averageWordLength(array) {
94+
let sum = 0;
95+
if (array.length === 0) {
96+
return null;
97+
}
98+
for ( let i = 0; i < array.length; i++){
99+
sum += array[i].length;
100+
}
101+
const average = sum / array.length;
102+
return average;
103+
}
104+
105+
106+
94107

95108
// Bonus - Iteration #4.1
96109
function avg() {}
@@ -110,7 +123,23 @@ const wordsUnique = [
110123
"bring",
111124
];
112125

113-
function uniquifyArray() {}
126+
function uniquifyArray(arr) {
127+
if (arr.length === 0) {
128+
return null;
129+
}
130+
131+
let newArray =[];
132+
for (let i = 0; i < arr.length; i++) {
133+
if (newArray.indexOf(arr[i]) === -1) {
134+
newArray.push(arr[i]);
135+
}
136+
}
137+
return newArray;
138+
}
139+
140+
141+
142+
114143

115144
// Iteration #6: Find elements
116145
const wordsFind = [

0 commit comments

Comments
 (0)