Guest User

Untitled

a guest
Feb 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. /*
  2. * Snippets collected during development: made by myself or found on StackOverflow/GitHub.
  3. * Collection will grow in time.
  4. * Enjoy.
  5. */
  6.  
  7. // --- removing duplicates from an array ---
  8. [2, 4, 5, 2, 6, 4].filter((el, i, arr) => arr.indexOf(el) === i);
  9. [2, 4, 5, 2, 6, 4].reduce((acc, curr) => acc.includes(curr) ? acc : [...acc, curr], []);
  10. [2, 4, 5, 2, 6, 4].reduce((acc, curr) => acc.includes(curr) ? acc : acc.concat(curr), []);
  11. [...new Set([2, 4, 5, 2, 6, 4])];
  12.  
  13. // --- flattening array of arrays ---
  14. [[2,4], [5,2,6], [4]].reduce((acc, curr) => acc.concat(curr));
  15.  
  16. // --- last element of array ---
  17. const arr = [2, 4, 5, 2, 6, 4];
  18. arr[arr.length - 1];
  19. const [last] = arr.splice(-1);
Add Comment
Please, Sign In to add comment