I am currently developing my own version of Tetris. My main focus at the moment is creating a function that can rotate a 2D variable array by 90 degrees (or -90).
For instance, if we have an array like:
"-T-",
"TTT"
The expected output should be:
"T-",
"TT",
"T-"
I attempted to implement this using the following function:
function rotateN90(a){
var temp = [];
for(var x = 0; x<a[0].length; x++){
temp.push("");
for(var y = 0; y<a.length; y++){
temp[x] += a[y][x];
}
}
return temp;
}
However, the current function is not producing the desired outcome. It does rotate the initial T-Block example by -90 degrees once, but then reverts back to its original orientation.
I would greatly appreciate any assistance with this problem!
(PS: I am working within KA's processing environment and do not have access to libraries or ES6 features.)