Skip to content

Instantly share code, notes, and snippets.

@jremi
Created April 6, 2016 22:42
Show Gist options
  • Save jremi/e4bff26c2bebd6b6326113a01140504d to your computer and use it in GitHub Desktop.
Save jremi/e4bff26c2bebd6b6326113a01140504d to your computer and use it in GitHub Desktop.
Small snippet to check if an array is fully uniform. All elements inside array must be same to produce true result. If they are different then the array is not uniform and false.
var falseTracker = 0;
isUniform(["2","2","2","2"]);
function isUniform(array) {
var firstElement = array[0];
array.shift();
array.forEach(function(element,index) {
if (firstElement !== element)
falseTracker = 1;
});
if(falseTracker === 1) {
console.log("false");
falseTracker = 0; //reset switch to re-use function.
}
else
console.log("true");
}
@AlexOros
Copy link

AlexOros commented Oct 5, 2017

Thank you, this helped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment