Skip to content

Instantly share code, notes, and snippets.

@bezenson
Last active August 25, 2020 22:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bezenson/2cc6e66b7ebd6623c5f33bd1b1cd07c1 to your computer and use it in GitHub Desktop.
Save bezenson/2cc6e66b7ebd6623c5f33bd1b1cd07c1 to your computer and use it in GitHub Desktop.
Ramda uniqWith by multiple keys in object
import { allPass, curry, eqProps, map, uniqWith } from 'ramda';
const uniqWithByFields = curry((fields, data) => uniqWith(
allPass(
map(eqProps)(fields)
),
)(data));
const data = [
{id: "001", val1: 1, val2: '1'},
{id: "002", val1: 1, val2: '1'},
{id: "003", val1: 2, val2: '5'},
];
uniqWithByFields(['val1', 'val2'], data); // [{"id": "001", "val1": 1, "val2": "1"}, {"id": "003", "val1": 2, "val2": "5"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment