Learn from Haskell - Functional, Reusable JavaScript: "function count(array, matching) {
var counted = 0
for (var i = 0; i < array.length; i++) {
if (matching(array[i]))
counted++
}
return counted
}
// == 2, same as first example
count([1,3,3,4,5], function(num) {
return (num == 3)
})
// == 2, now we can use our functions for ANY kind of items or match test!
count([{name:"bob"}, {name:"henry"}, {name:"jon"}], function(obj) {
return (obj.name.length < 4)
})"
'via Blog this'