Skip to content

Instantly share code, notes, and snippets.

@stiller
Last active October 27, 2021 10:21
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 stiller/d5e41303358f8900c2f0eef39b268dec to your computer and use it in GitHub Desktop.
Save stiller/d5e41303358f8900c2f0eef39b268dec to your computer and use it in GitHub Desktop.
anna
input = [ { personId: 1, color: 'red' }, { personId: 2, color: 'red' } ]
personIds = [...new Set(input.map(e => e.personId))]
//add 'green'
personIds.forEach(personId => input.push({ personId, color: 'green' }))
//remove 'green'
input = input.filter(item => item.color !== 'green')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment