Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Array.prototype.difference = function(arr) {
- var flag = (arr.length > this.length);
- var tempArr1 = flag ? arr.slice(0) : this.slice(0);
- var tempArr2 = flag ? this.slice(0): arr.slice(0);
- var newArr = [];
- tempArr1.forEach(function(val, pos) {
- var index = tempArr2.indexOf(val);
- if(index > -1)
- tempArr2.splice(index, 1);
- else
- newArr.push(val);
- });
- return newArr.concat(tempArr2);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement