Skip to content

Instantly share code, notes, and snippets.

@sererejegede
Last active December 12, 2021 07:14
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 sererejegede/640fb4ecbfc803f81956b03a57d2fc2c to your computer and use it in GitHub Desktop.
Save sererejegede/640fb4ecbfc803f81956b03a57d2fc2c to your computer and use it in GitHub Desktop.
/**
* @param {Array} arr - Array to be filtered from
* @param {Array} props - array of keys that needs to be unique
* @returns {Array} - unique array
*/
const unique = (arr, props = []) => [...new Map(arr.map(entry => [props.map(k => entry[k]).join('|'), entry])).values()]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment