Here is the code snippet I am working with:
var points = 4;
var yModifier = [];
for (var i = 0; i <= points; i++) {
yModifier.push([]);
};
yModifier.forEach(
(a, j) => {
var start = j;
var end = start + points;
for (var i = start, k = 0; i <= end; i++, k++) {
yModifier[j].push([k, i])
};
}
);
console.log(yModifier);
This code produces the following output:
0: [[0,0],[1,1],[2,2],[3,3],[4,4]]
1: [[0,1],[1,2],[2,3],[3,4],[4,5]]
2: [[0,2],[1,3],[2,4],[3,5],[4,6]]
3: [[0,3],[1,4],[2,5],[3,6],[4,7]]
4: [[0,4],[1,5],[2,6],[3,7],[4,8]]
I want to modify the forEach
section to achieve the following desired output:
0: [[0,0],[1,1],[2,2],[3,3],[4,4]]
1: [[0,-1],[1,0],[2,1],[3,2],[4,3]]
2: [[0,-2],[1,-1],[2,0],[3,1],[4,2]]
3: [[0,-3],[1,-2],[2,-1],[3,0],[4,1]]
4: [[0,-4],[1,-3],[2,-2],[3,-1],[4,0]]