difference between two arrays in javascript
something like so:
Array.prototype.difference = function(other) { var a = this.inject($H(), function(h, v) { h.set(v, true); return h; }); other.each(function(v) { this.unset(v); }.bind(a)); return a.keys(); }
which lets you do this:
>>> [2,3,4].difference([5,6,7]) 2,3,4 >>> [2,3,4].difference([5,6,7,4]) 2,3 >>> [2,3,4].difference([2,3,4]) []
About this entry
You’re currently reading “difference between two arrays in javascript,” an entry on e-huned.com
- Published:
- 12.27.08 / 4pm
- Category:
- personal
No comments
Jump to comment form | comments rss [?] | trackback uri [?]