Skip to content

Instantly share code, notes, and snippets.

@aneurysmjs
Created April 19, 2018 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aneurysmjs/61d3e635d2f8e0dc8ce0f8fc1254bd91 to your computer and use it in GitHub Desktop.
Save aneurysmjs/61d3e635d2f8e0dc8ce0f8fc1254bd91 to your computer and use it in GitHub Desktop.
filtering nested array of obejct using Ramda.js
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