Skip to content

Instantly share code, notes, and snippets.

@uguisu-an
Created June 26, 2019 11:31
Show Gist options
  • Save uguisu-an/9415dbf8a952c56acd1518f82b273ac7 to your computer and use it in GitHub Desktop.
Save uguisu-an/9415dbf8a952c56acd1518f82b273ac7 to your computer and use it in GitHub Desktop.
集合同士の処理例
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