Guest User

Untitled

a guest
May 27th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.27 KB | None | 0 0
  1. function squish(arr) {
  2. function accumulate(acc, val, i) {
  3. if(val === arr[i-1]) {
  4. let tuple = acc[i-1];
  5. tuple[1]++;
  6. acc[i] = tuple
  7. delete acc[i-1];
  8. } else {
  9. acc[i] = [val, 1];
  10. }
  11. return acc;
  12. };
  13. return arr.reduce(accumulate, []).filter(x=>x!==undefined);
  14. }
Add Comment
Please, Sign In to add comment