Last active
August 25, 2020 22:19
-
-
Save bezenson/2cc6e66b7ebd6623c5f33bd1b1cd07c1 to your computer and use it in GitHub Desktop.
Ramda uniqWith by multiple keys in object
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
import { allPass, curry, eqProps, map, uniqWith } from 'ramda'; | |
const uniqWithByFields = curry((fields, data) => uniqWith( | |
allPass( | |
map(eqProps)(fields) | |
), | |
)(data)); |
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 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