Skip to content

Instantly share code, notes, and snippets.

@suissa
Created August 26, 2018 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suissa/dbe2ed4d7d4d505b3ac9893ddc98180a to your computer and use it in GitHub Desktop.
Save suissa/dbe2ed4d7d4d505b3ac9893ddc98180a to your computer and use it in GitHub Desktop.
JavaScript - groupby - filter 02
const toGroup = (field, value) => (obj) =>
obj[field] === value
const filtered = list.filter(toGroup("level", "senior"))
console.log({filtered})
/**
{ filtered:
[ { id: 1,
name: 'Suissa',
active: true,
level: 'senior',
tags: [Array] },
{ id: 2,
name: 'Bella',
active: true,
level: 'senior',
tags: [Array] },
{ id: 3,
name: 'Joana',
level: 'senior',
active: true,
tags: [Array] } ] }
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment