Guest User

Untitled

a guest
Jun 21st, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. "use strict";
  2.  
  3. // head :: Array a → a
  4. const head = ([head, ...tail]) => head;
  5. // tail :: Array a → Array a
  6. const tail = ([head, ...tail]) => tail;
  7.  
  8. // unique :: Array Number → Array Number
  9. const unique = ( ls, acc = [] ) => {
  10. if ( ls.length === 0) return acc;
  11. if ( acc.indexOf( head( ls ) ) == -1 ) return unique( tail( ls ), acc.concat( head( ls ) ) );
  12. return unique( tail( ls ), acc );
  13. }
  14.  
  15. const nums = [1,2,5,7,4,0,33,48,3,8,4,569,0,23,4,1,9];
  16.  
  17. console.log(
  18. unique(nums)
  19. )
Add Comment
Please, Sign In to add comment