Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function collapse(array) {
- let l = array.length, i = 0, arr = [], item = [];
- while (l--) {
- const curr = array[i];
- const next = array[i + 1];
- item.length === 0 && item.push(curr);
- if (curr !== next - 1) {
- item.length === 1 && item.push(curr);
- }
- if (item.length === 2) {
- arr.push(item.slice());
- item = [];
- }
- i++;
- }
- return arr;
- }
- function changeRng(rng, notInRange) {
- const newRng = [];
- const start = notInRange[0];
- const end = notInRange[1];
- let l = rng.length, i = 0;
- while (l--) {
- const rr = rng[i++];
- rr[1] < start && newRng.push(rr);
- if (rr[1] > start && rr[0] < start) {
- newRng.push([rr[0], start - 1]);
- rr[1] > end && newRng.push([end + 1, rr[1]]);
- }
- rr[0] > end && newRng.push(rr);
- }
- return newRng;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement