Created
April 19, 2018 16:32
-
-
Save aneurysmjs/61d3e635d2f8e0dc8ce0f8fc1254bd91 to your computer and use it in GitHub Desktop.
filtering nested array of obejct using Ramda.js
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
const data = [ | |
{username: 'bob', age: 30, tags: ['work', 'boring']}, | |
{username: 'jim', age: 25, tags: ['home', 'fun']}, | |
{username: 'jane', age: 30, tags: ['vacation', 'fun']} | |
]; | |
R.filter(R.where({tags: R.contains('fun')}))(data); | |
const users = [ | |
{username: 'bob', age: 30, tags: [{label: 'work'}, {label: 'boring'}]}, | |
{username: 'jim', age: 25, tags: [{label: 'home'}, {label: 'fun'}]}, | |
{username: 'jane', age: 30, tags: [{label: 'vacation'}, {label: 'fun'}]} | |
]; | |
const hasFunTag = R.any(R.propEq('label', 'fun')) | |
R.filter(R.compose(hasFunTag, R.prop('tags')))(users) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment