I have a matrix of strings that looks like this:
stringMatrix = `
1 0 0
0 1 0
0 0 0
`
I am looking for a way to convert it into a double array: [[1,0,0], [0,1,0], [0,0,1]]
, is there a more elegant js-y solution to achieve this?
I attempted
matrix = values[0].trim().split('\n');
, but it only separates the outer layer into: ["1 0 0", "0 1 0", "0 0 0"]
; I could use a for-loop, but I was hoping for a solution involving lambda expressions or fat arrows.
//plain vanilla javascript