I have several inputs, let's say here are two inputs like the following:
const first = 50;
const second = [[14, 16], [28, 30]];
How can i get the following result:
expected result = [[0, 13], [14, 16], [17, 27], [28, 30], [31, 50]];
Now my code is like this and still confused to arrange the correct logic, thank you
const first = 50;
const second = [[14, 16], [28, 30]].flat(1);
let result = [];
for(let i = 0; i < second.length; i++) {
let temp = second[i];
if (i === 0) {
result.push([i, temp - 1]);
}
result.push([i+temp, temp+2]);
}
console.log(result); // output [[0, 13], [14, 16], [17, 18], [30, 30], [33, 32]]