I've encountered a problem with the code snippet below:
function isUniform (arr) {
arr.forEach (function (el){
console.log (el);
if (arr [0] !== el) {
return (false);
}
})
return (true);
}
console.log (isUniform ([1, 1, 1, 1]));
console.log (isUniform ([2, 1, 1, 1]));
console.log (isUniform (["a", "b", "p"]));
console.log (isUniform (["b", "b", "b"]));
The intended functionality was for it to return "true" when all elements in an array are identical, and "false" otherwise. However, I'm facing an issue where it consistently returns "true". Upon further investigation, I discovered that JavaScript seems to be skipping over the single "if" statement.
UPDATE: This post is not a duplicate as I am seeking advice regarding my own code. Specifically, I wish to understand why the "if" statement nested within the forEach loop is being overlooked, which has not been addressed in similar queries.