Created
February 17, 2016 11:37
-
-
Save digitalkaoz/ca14eeb60b665328101b to your computer and use it in GitHub Desktop.
JS Array diffing with objects that respect duplicates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _ = require('underscore'); | |
var a = [{type: 'green'}]; | |
var b = [{type: 'green'},{type: 'green'}]; | |
var onlyInA = a.filter((current) => { | |
return b.filter((current_b) => { | |
return _.isEqual(current, current_b); | |
}).length == 0 | |
}); | |
var onlyInB = b.filter((current) => { | |
return a.filter((current_a) => { | |
return _.isEqual(current, current_a); | |
}).length == 0 | |
}); | |
var diff = onlyInA.concat(onlyInB); | |
console.log(diff); | |
//expected [{type:'green'}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment