Created
June 26, 2019 11:31
-
-
Save uguisu-an/9415dbf8a952c56acd1518f82b273ac7 to your computer and use it in GitHub Desktop.
集合同士の処理例
This file contains hidden or 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
const _ = require("lodash"); | |
const xs = [ | |
{ | |
id: 1, | |
name: "John Doe" | |
}, | |
{ | |
id: 2, | |
name: "Jane Doe" | |
} | |
] | |
const ys = [ | |
{ | |
id: 2, | |
name: "Jane Duck" | |
}, | |
{ | |
id: 3, | |
name: "Jack Nicholson" | |
} | |
] | |
console.info(_.differenceBy(xs, ys, "id")); //=> 1 | |
console.info(_.differenceBy(ys, xs, "id")); //=> 3 | |
console.info(_.intersectionBy(xs, ys, "id")); //=> 2 | |
console.info(_.intersectionBy(ys, xs, "id")); //=> 2 | |
console.info(_.unionBy(xs, ys, "id")); //=> 1, 2, 3 | |
console.info(_.unionBy(ys, xs, "id")); //=> 2, 3, 1 | |
console.info(_.xorBy(xs, ys, "id")); //=> 1, 3 | |
console.info(_.xorBy(ys, xs, "id")); //=> 3, 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment