Created
April 6, 2016 22:42
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, this helped.