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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…