You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//function 'sum' already accepts string data types
72
+
functionaverageWordLength(wordsArr){
73
+
if(wordsArr.length===0){
74
+
returnnull;
75
+
}
76
+
returnsum(wordsArr)/wordsArr.length;
77
+
}
68
78
69
79
// Bonus - Iteration #4.1
70
-
functionavg(){}
80
+
functionavg(list){
81
+
if(list.length===0){
82
+
returnnull;
83
+
}
84
+
returnsum(list)/list.length;
85
+
}
71
86
72
87
// Iteration #5: Unique arrays
73
88
constwordsUnique=[
@@ -84,14 +99,29 @@ const wordsUnique = [
84
99
'bring'
85
100
];
86
101
87
-
functionuniquifyArray(){}
102
+
functionuniquifyArray(list){
103
+
//check if the list is empty
104
+
if(list.length===0){
105
+
returnnull;
106
+
}
107
+
//We will use a set. A set is basically an array but it can only hold unique values. Let's make a set out of the array.
108
+
letresult=newSet(list);
109
+
//The 'set' is actually an object.
110
+
//We need to give the values stored in the set into an array back again. Just put it into brackets to 'array-fy' the set, then use the spread operator to separate the values into different elements of the array.
0 commit comments