I am currently working on a function that needs to return true if an array contains all integers, and false if it does not. I am incorporating the every method for this purpose, which is documented on MDN here.
For example, if the input is '1234', the function should return true, whereas if the input is '123a', it should return false.
function validatePIN(pin) {
let pinArray = pin.split("");
if (pinArray.length === 4 || pinArray.length === 6) {
if (pinArray.every(element => !isNaN(element))) {
return true;
}
}
}
I am curious about the mechanism by which the every method passes each element to isInteger for testing. How exactly does this process work?