Typescript | 二维数组(泛型)矩阵行列互换
程序员文章站
2022-03-05 08:13:17
...
/*
* @Author: Prpr_Saber
* @Date: 2018-11-02 17:06:29
* @Last Modified by: Prpr_Saber
* @Last Modified time: 2018-11-02 21:41:47
*/
export let transformArray: <Type>(
arr: Type[][]
) => Type[][] = function transformArray<Type>(arr: Type[][]): Type[][] {
let newArray: Array<Array<Type>> = new Array<Array<Type>>()
let raws = arr.length
let raw = 0
for (; raw < raws; raw++) {
newArray.push([])
let col = 0
let cols = arr[raw].length
for (; col < cols; col++) {
newArray[raw][col] = arr[col][raw]
}
}
return newArray
}
上一篇: web项目中使用多线程的一些坑