Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function squish(arr) {
- function accumulate(acc, val, i) {
- if(val === arr[i-1]) {
- let tuple = acc[i-1];
- tuple[1]++;
- acc[i] = tuple
- delete acc[i-1];
- } else {
- acc[i] = [val, 1];
- }
- return acc;
- };
- return arr.reduce(accumulate, []).filter(x=>x!==undefined);
- }
Add Comment
Please, Sign In to add comment