Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Snippets collected during development: made by myself or found on StackOverflow/GitHub.
- * Collection will grow in time.
- * Enjoy.
- */
- // --- removing duplicates from an array ---
- [2, 4, 5, 2, 6, 4].filter((el, i, arr) => arr.indexOf(el) === i);
- [2, 4, 5, 2, 6, 4].reduce((acc, curr) => acc.includes(curr) ? acc : [...acc, curr], []);
- [2, 4, 5, 2, 6, 4].reduce((acc, curr) => acc.includes(curr) ? acc : acc.concat(curr), []);
- [...new Set([2, 4, 5, 2, 6, 4])];
- // --- flattening array of arrays ---
- [[2,4], [5,2,6], [4]].reduce((acc, curr) => acc.concat(curr));
- // --- last element of array ---
- const arr = [2, 4, 5, 2, 6, 4];
- arr[arr.length - 1];
- const [last] = arr.splice(-1);
Add Comment
Please, Sign In to add comment