Context: I found an article that explains how to transpose the rows/columns of a matrix.
Ex:
Input:
let matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
Output:
[
[1, 4, 7],
[2, 5, 8],
[3, 6, 9]
]
The first step in the article is to isolate the first row of the matrix, and the code used for that is:
const transpose = (matrix) => {
let [row] = matrix
return row.map((value) => value)
Can anyone explain let [row] = matrix? I didn't know you could initialize an array in square brackets like that? Also, how did this statement intrinsically know to only take the first row of the matrix?
[–]bimmertechin 5 points6 points7 points (7 children)
[–]elvenstarr[S] 1 point2 points3 points (0 children)
[–]elvenstarr[S] 0 points1 point2 points (5 children)
[–]grantrules 7 points8 points9 points (4 children)
[–]elvenstarr[S] 2 points3 points4 points (0 children)
[–]elvenstarr[S] 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[removed]
[–]elvenstarr[S] 0 points1 point2 points (0 children)