I am trying to create a multi dimensional array based off of the calculations of another 3D array.
Input array is in format [shift, start Num, end num]
I should be clear the "," is just for visual purposes.
I need each value in its own array location i.e. [value1]=location 0,0
[value2]=location 0,1
[value3]=location 0,2
etc.
Example:
aInput looks like this
[0,1,5]
[1,1,3]
[2,1,2]
aOutput should look like this
[1,1,1]
[1,1,2]
[1,2,1]
[1,2,2]
[1,3,1]
[1,3,2]
[2,1,1]
[2,1,2]
[2,2,1]
[2,2,2]
[2,3,1]
[2,3,2]
[1,3,2]
[3,1,1]
[3,1,2]
[3,2,1]
[3,2,2]
[3,3,1]
[3,3,2]
[etc]
It needs to increase the number of items in the array based on the shift. i.e 0 = shift would be 1 column, shift = 1 would be 2 columns, shift = 3 would be 3 columns, and so on. This is what I have so far, but I can not figure out how to make it calculate for anything with a shift.
var aInput = new Array();
aInput[0] = new Array("0", "1","5");
aInput[1] = new Array("1", "1","3");
aInput[2] = new Array("2", "1","2");
for (var x=0; x < aInput[x].length; x++){
//Calculate out number
if (aInput[x][0] == 0){ // Im sure this should be a loop of some sort, just not sure how to do it
var i=Number(aInput[x][1]);
while (i <= Number(aInput[x][2])){
//Write to output array
aOutput.push(i);
i++;
}
}
}
Thanks in advance for any help, I'm really stumped on this one.
myArr[1]
supposed to beaInput[1]
? Do you meanaInput = [[0, 1, 5], [1, 1, 3], [2, 1, 2]];
? – Barmar Apr 29 at 23:27