Check if each item in an array is identical in javascript -
i need test whether each item in array identical each other. example:
var list = ["l","r","b"]
should evaluate false, because each item not identical. on other hand this:
var list = ["b", "b", "b"]
should evaluate true because identical. efficient (in speed/resources) way of achieving this?
function identical(array) { for(var = 0; < array.length - 1; i++) { if(array[i] !== array[i+1]) { return false; } } return true; }
Comments
Post a Comment