@@ -54,12 +54,14 @@ function sum(itemsArray) {
54
54
sumItems += itemsArray [ i ]
55
55
} else if ( typeof itemsArray [ i ] === "string" ) {
56
56
sumItems += itemsArray [ i ] . length
57
- } else if ( typeof itemsArray [ i ] === "boolean" ) {
57
+ } else if ( itemsArray [ i ] === true ) {
58
58
sumItems += 1
59
+ } else if ( itemsArray [ i ] === false ) {
60
+ sumItems += 0
59
61
} else if ( typeof itemsArray [ i ] === "object" ) {
60
- return " Error"
62
+ throw new Error ( "Unsupported data type sir or ma'am" )
61
63
} else if ( typeof itemsArray [ i ] === "array" ) {
62
- return " Error"
64
+ throw new Error ( "Unsupported data type sir or ma'am" )
63
65
}
64
66
}
65
67
return sumItems
@@ -72,7 +74,7 @@ sum(mixedArr)
72
74
const numbersAvg = [ 2 , 6 , 9 , 10 , 7 , 4 , 1 , 9 ]
73
75
74
76
function averageNumbers ( arrayNumbers ) {
75
- if ( arrayNumbers . length === 0 ) return 0
77
+ if ( arrayNumbers . length === 0 ) return null
76
78
77
79
const average = sum ( arrayNumbers ) / arrayNumbers . length
78
80
return average
@@ -101,7 +103,8 @@ const anotherMixedArr = [6, 12, 'miami', 1, true, 'barca', '200', 'lisboa', 8, 1
101
103
102
104
function avg ( itemsArray ) {
103
105
if ( itemsArray . length === 0 ) return null
104
- return sum ( itemsArray ) / itemsArray . length
106
+ const result = Math . floor ( ( sum ( itemsArray ) / itemsArray . length ) * 100 ) / 100
107
+ return result
105
108
}
106
109
107
110
avg ( anotherMixedArr )
@@ -126,9 +129,12 @@ function uniquifyArray(arr) {
126
129
if ( arr . length === 0 ) return null
127
130
128
131
for ( i = 0 ; i < arr . length ; i ++ ) {
129
- for ( j = ++ i ; j < arr . length ; j ++ ) {
132
+ console . log ( `i = ${ i } ` )
133
+ for ( j = i + 1 ; j < arr . length ; j ++ ) {
134
+ console . log ( `j = ${ j } ` )
130
135
if ( arr [ i ] === arr [ j ] ) {
131
136
arr . splice ( j , 1 ) ;
137
+ console . log ( arr )
132
138
}
133
139
}
134
140
}
@@ -169,7 +175,7 @@ const wordsCount = [
169
175
] ;
170
176
171
177
function howManyTimes ( arr , word ) {
172
- if ( arr . length === 0 ) return null
178
+ if ( arr . length === 0 ) return 0
173
179
let wordTimes = 0
174
180
for ( i = 0 ; i < arr . length ; i ++ ) {
175
181
if ( arr [ i ] === word ) {
0 commit comments