Issue
I am currently working on a function that evaluates an array to determine if all elements inside the array are identical. If they are, it should return true; otherwise, it should return false. However, I do not want the function to return true/false for each individual element, but rather for the entire array as a whole.
Solution Attempt 1
The following method works, but it provides true/false output for each element in the array:
function isUniform(arr){
let first = arr[0];
for (let i = 1; i <arr.length; i++){
if (arr[0] !== arr[i]){
console.log(false);
} else {
console.log(true);
}
}
}
Solution Attempt 2
This method returns true/false initially and then prints true again at the end:
function isUniform(arr){
let first = arr[0];
for (let i = 1; i <arr.length; i++){
if (arr[0] !== arr[i]){
console.log(false);
}
}
console.log(true);
}