I am working with an array of numbers that is structured like this:
const arrayOfArrays: number[][] = [[1, 2], [1, 3]];
The desired outcome is to have [[1, 2], [2, 1], [1, 3], [3, 1]]
.
I found a solution using the following approach:
// initialize an empty array
let result: number[][] = [];
for (const elArr of arrayOfArrays) {
result.push(elArr);
result.push(elArr.reverse());
}
However, I believe there might be more elegant ways to achieve this. Any suggestions?