Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

CLooker Dec 7th, 2017 56 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. // return an array with no duplicates
  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.find(uniqueItem => uniqueItem === item) === undefined
  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));
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top