I need to be able to mirror a multidimensional array that changes in size. I'm currently hard coding for each particular array size and it is horribly inefficient.
Example:
Arr1 { 1 2 3 Arr2 { 1 2
4 5 6 3 4
7 8 9 } 5 6 }
Mirrored:
{ 3 2 1 { 2 1
6 5 4 4 3
9 8 7 } 6 5 }
Arrays range in size from 2x5 to 4x10.
Ok, so all you need is a horizontal mirror. I suppose that your array contains an array for every line, so that means that you just need to reverse every row.
for(var i=0;i<multiarr.length;i++){
multiarr[i].reverse();
}
or even better
multiarr.map(function(arr){return arr.reverse();});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With