Files
gitmost/packages/editor-ext/src/lib/table/utils/transpose.ts
T
Mirone 7d1e5bce0d feat: table row/column drag and drop (#1467)
* chore: add dev container

* feat: add drag handle when hovering cell

* feat: add column drag and drop

* feat: add support for row drag and drop

* refactor: extract preview controllers

* fix: hover issue

* refactor: add handle controller

* chore: f

* chore: remove log

* chore: remove dev files

* feat: hide other drop indicators when table dnd working

* feat: add auto scroll and bug fix

* chore: f

* fix: firefox
2025-08-31 18:53:27 +01:00

30 lines
679 B
TypeScript

/**
* Transposes a 2D array by flipping columns to rows.
*
* Transposition is a familiar algebra concept where the matrix is flipped
* along its diagonal. For more details, see:
* https://en.wikipedia.org/wiki/Transpose
*
* @example
* ```javascript
* const arr = [
* ['a1', 'a2', 'a3'],
* ['b1', 'b2', 'b3'],
* ['c1', 'c2', 'c3'],
* ['d1', 'd2', 'd3'],
* ];
*
* const result = transpose(arr);
* result === [
* ['a1', 'b1', 'c1', 'd1'],
* ['a2', 'b2', 'c2', 'd2'],
* ['a3', 'b3', 'c3', 'd3'],
* ]
* ```
*/
export function transpose<T>(array: T[][]): T[][] {
return array[0].map((_, i) => {
return array.map((column) => column[i])
})
}