Skip to content

Instantly share code, notes, and snippets.

@wewindy
Created February 25, 2021 11:02
Show Gist options
  • Save wewindy/fe1e2698963cb9edb2a8b28b2dbebb20 to your computer and use it in GitHub Desktop.
Save wewindy/fe1e2698963cb9edb2a8b28b2dbebb20 to your computer and use it in GitHub Desktop.
array[][] transpose
/**
* 将矩阵(二维数组形式)转置的高效方法
* @param {Array[][]} arr 二维数组,子数组中元素个数应一致
*/
export function transpose(arr) {
return arr[0].map((_, i) => arr.map(row => row[i]))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment