Advertisement
CLooker

Untitled

Dec 7th, 2017
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // return an array with no duplicates *improved
  2.  
  3. let animals = ['cat', 'dog', 'cat', 'dog'];
  4. let booleans = [true, false, true, false];
  5. let nums = [1,2,1,2];
  6. let mixture = ['cat', true, 1, 'cat', true, 1];
  7.  
  8.  
  9. const returnNoDuplicates = (arr) => {
  10.   return arr.reduce((newArr, item) => {
  11.     newArr.includes(item) === false
  12.     ? newArr.push(item)
  13.     : null
  14.     return newArr;
  15.   }, [])
  16. };
  17.  
  18. console.log(returnNoDuplicates(animals));
  19. console.log(returnNoDuplicates(booleans));
  20. console.log(returnNoDuplicates(nums));
  21. console.log(returnNoDuplicates(mixture));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement