I am having trouble witht he following piece of code:
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"]));
It was supposed to return "true" when all elements in an array are identical, and "false" otherwise, but it keeps returning "true", and through testing I found out that JavaScript skips over the only "if" statement.
EDIT: Not a duplicate because I'm asking for advice on my own code. Specifically about why the "if" statement nested inside forEach was being ignored, which isn't covered in other questions.