Skip to content

Instantly share code, notes, and snippets.

@mandaputtra
Created January 7, 2019 06:40
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 mandaputtra/566d3e3751011cdd0da30305f033380e to your computer and use it in GitHub Desktop.
Save mandaputtra/566d3e3751011cdd0da30305f033380e to your computer and use it in GitHub Desktop.
Simple JavaScript shortcut

Eliminating all duplicates in array with reduce() reduce take 4 params previousValue, currentValue, index, array

array.reduce((acc, el, i, arr) => {
    if (arr.indexOf(el) !== i && acc.indexOf(el) < 0) acc.push(el); return acc;
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment