Skip to content

@drwlrsn /6.1.js secret

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Eloquent JavaScript
'use strict';
var forEach = function (array, action) {
for (var i = 0; i < array.length; i++) {
action(array[i]);
}
};
var reduce = function (combine, base, array) {
forEach(array, function (element) {
base = combine(base, element);
});
return base;
};
var count = function (test, numbers) {
return reduce(function (total, number) {
if (number === test) {
return total + 1;
}
return total;
}, 0, numbers);
};
var countZeroes = function (numbers) {
return count(0, numbers);
};
// Test!
console.log( countZeroes([5, 6, 0, 3, 5, 7, 0, 0, -0]) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.