Return to Snippet

Revision: 64794
at September 21, 2013 00:39 by uberdragon


Initial Code
Array.prototype.AllValuesSame = function(){

    if(this.length > 0) {
        for(var i = 1; i < this.length; i++)
        {
            if(this[i] !== this[0])
                return false;
        }
    } 
    return true;
}

Initial URL

                                

Initial Description
Usage: 
var a = ['a','a','a'];
var b = a.AllValuesSame(): //true

var a ['1','1','2'];
var b = a.AllValuesSame(); //false

Initial Title
Method to determine if all values in an array are the same.

Initial Tags
array

Initial Language
JavaScript