Wednesday, May 20, 2015

Comparing arrays in Java Script

A sample on how to compare two arrays :


Array.prototype.diff = function(a) {
    return this.filter(function(i) {return a.indexOf(i) < 0;});
};
var a = ['b','c'];
var b = ['b','c','d','e','f'];
var temp = a.diff(b);
temp.length;

Credits : Nikhil

No comments:

Post a Comment