We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e557792 commit 1510060Copy full SHA for 1510060
src/functions-and-arrays.js
@@ -86,6 +86,26 @@ function averageWordLength(words) {
86
87
//Bonus
88
89
+function avg(arr) {
90
+ if (arr.length<=0) {
91
+ return null
92
+ }
93
+ let result = 0;
94
+ for (let i = 0; i < arr.length; i++) {
95
+
96
+ if( typeof arr[i] == 'boolean') {
97
+ result += arr[i]
98
+ } else if( typeof arr[i] == 'number') {
99
100
+ } else if( typeof arr[i] == 'string') {
101
+ result += arr[i].length
102
+ } else {
103
+ throw new Error("Unsupported data type sir or ma'am")
104
105
106
+ return Math.floor((result / arr.length) * 100) /100
107
+}
108
109
// Iteration #5: Unique arrays
110
const wordsUnique = [
111
'crab',
0 commit comments