I currently have an array set up like this
0: (5) ["2", "X", "8", "11", "15"]
1: (5) ["1", "5", "X", "X", "14"]
2: (5) ["X", "4", "7", "10", "13"]
3: (5) ["X", "3", "6", "9", "12"]
My goal is to swap the position of the digit 1 with the position of digit 2 in order to get this desired outcome:
0: (5) ["1", "X", "8", "11", "15"]
1: (5) ["2", "5", "X", "X", "14"]
2: (5) ["X", "4", "7", "10", "13"]
3: (5) ["X", "3", "6", "9", "12"]
This array is returned all at once, so I need a way to rearrange the elements after it's returned.
Currently, I am working with JavaScript. Thank you in advance for any help or suggestions.
I attempted to use the following code snippet:
Array.prototype.move = function (from, to) {
this.splice(to, 0, this.splice(from, 1)[0]);
};
However, this code ends up moving entire rows together, rather than just swapping individual digits within the arrays.