@humanspeak/svelte-headless-table
Version:
A powerful, headless table library for Svelte that provides complete control over table UI while handling complex data operations like sorting, filtering, pagination, grouping, and row expansion. Build custom, accessible data tables with zero styling opin
24 lines (23 loc) • 669 B
JavaScript
export const getNullMatrix = (width, height) => {
const result = [];
// Use a loop to create a new array instance per row.
for (let i = 0; i < height; i++) {
result.push(Array(width).fill(null));
}
return result;
};
export const getTransposed = (matrix) => {
const height = matrix.length;
if (height === 0) {
return matrix;
}
const width = matrix[0].length;
const result = getNullMatrix(height, width);
for (let i = 0; i < width; i++) {
for (let j = 0; j < height; j++) {
result[i][j] = matrix[j][i];
}
}
// We guarantee that all elements are filled.
return result;
};