Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict";
- // head :: Array a → a
- const head = ([head, ...tail]) => head;
- // tail :: Array a → Array a
- const tail = ([head, ...tail]) => tail;
- // unique :: Array Number → Array Number
- const unique = ( ls, acc = [] ) => {
- if ( ls.length === 0) return acc;
- if ( acc.indexOf( head( ls ) ) == -1 ) return unique( tail( ls ), acc.concat( head( ls ) ) );
- return unique( tail( ls ), acc );
- }
- const nums = [1,2,5,7,4,0,33,48,3,8,4,569,0,23,4,1,9];
- console.log(
- unique(nums)
- )
Add Comment
Please, Sign In to add comment