In here
it says that this should work:
function isPrime(element, index, array) {
var start = 2;
while (start <= Math.sqrt(element)) {
if (element % start++ < 1) return false;
}
return (element > 1);
}
console.log( [4, 5, 8, 12].find(isPrime) ); // 5
But I end up having an error:
TypeError: undefined is not a function
Why is that?
P.S.
I'm trying not to use underscorejs library since the browsers are supposed to support functions like find()
already.