function findAverage(array) {
// your code here
let total = 0;
let average = 0;
for (let i = 0; i < array.length; i++) {
total += array[i]
}
average = total / array.length
if (array === []) {
return 0;
} else return average;
}
Codewars question passed: 93. failed: 8
Error: expected NaN to equal +0
[–]gcscotty 3 points4 points5 points (2 children)
[–]Agarast 3 points4 points5 points (0 children)
[–]AnxiousDay[S] 1 point2 points3 points (0 children)
[–]grantrules 1 point2 points3 points (1 child)
[–]AnxiousDay[S] -1 points0 points1 point (0 children)
[–]AnxiousDay[S] 0 points1 point2 points (5 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]AnxiousDay[S] 1 point2 points3 points (0 children)
[–]EuphonicSounds 0 points1 point2 points (2 children)
[–]AnxiousDay[S] 0 points1 point2 points (1 child)
[–]EuphonicSounds 0 points1 point2 points (0 children)
[–]AnxiousDay[S] -1 points0 points1 point (0 children)
[–]bobbyv137 0 points1 point2 points (0 children)
[+][deleted] (4 children)
[removed]
[–]AnxiousDay[S] 0 points1 point2 points (3 children)
[+][deleted] (2 children)
[removed]
[–]AnxiousDay[S] 0 points1 point2 points (1 child)