Skip to content

Instantly share code, notes, and snippets.

@bjruberg
Last active October 6, 2018 10:08
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 bjruberg/f1316fc7f33cc1c35f3b8ea4bfa44c73 to your computer and use it in GitHub Desktop.
Save bjruberg/f1316fc7f33cc1c35f3b8ea4bfa44c73 to your computer and use it in GitHub Desktop.
const prepareArray = (arr, field) =>
if Array.isArray(arr) {
return arr.reduce((res, cur) => (res.length === 0 || cur[field] !== res[res.length - 1][field] ? [...res, cur] : res), [])
}
return []
}
prepareArray(someDataCollection, "value")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment