欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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
}

 

相关标签: typescript