Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. function collapse(array) {
  2. let l = array.length, i = 0, arr = [], item = [];
  3. while (l--) {
  4. const curr = array[i];
  5. const next = array[i + 1];
  6. item.length === 0 && item.push(curr);
  7. if (curr !== next - 1) {
  8. item.length === 1 && item.push(curr);
  9. }
  10. if (item.length === 2) {
  11. arr.push(item.slice());
  12. item = [];
  13. }
  14. i++;
  15. }
  16. return arr;
  17. }
  18.  
  19.  
  20. function changeRng(rng, notInRange) {
  21. const newRng = [];
  22. const start = notInRange[0];
  23. const end = notInRange[1];
  24. let l = rng.length, i = 0;
  25. while (l--) {
  26. const rr = rng[i++];
  27. rr[1] < start && newRng.push(rr);
  28. if (rr[1] > start && rr[0] < start) {
  29. newRng.push([rr[0], start - 1]);
  30. rr[1] > end && newRng.push([end + 1, rr[1]]);
  31. }
  32. rr[0] > end && newRng.push(rr);
  33. }
  34. return newRng;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement