MCPcopy
hub / github.com/baidu/amis / fillMatrix

Function fillMatrix

packages/office-viewer/src/excel/formula/functions/reference.ts:354–384  ·  view source on GitHub ↗
(array: number[][] | number[], fill_value?: number)

Source from the content-addressed store, hash-verified

352}
353
354export function fillMatrix(array: number[][] | number[], fill_value?: number) {
355 if (!array) {
356 throw FormulaError.VALUE;
357 }
358 let matrix: number[][];
359 // 兼容一维数组的情况
360 if (isOneDimensionalArray(array)) {
361 matrix = [[...(array as number[])]];
362 } else {
363 matrix = array as number[][];
364 }
365
366 matrix.map((arr, i) => {
367 arr.map((a, j) => {
368 if (!a) {
369 matrix[i][j] = 0;
370 }
371 });
372 });
373
374 const longestArrayIndex = matrix.reduce(
375 (acc, arr, i) => (arr.length > matrix[acc].length ? i : acc),
376 0
377 );
378 const longestArrayLength = matrix[longestArrayIndex].length;
379
380 return matrix.map(el => [
381 ...el,
382 ...Array(longestArrayLength - el.length).fill(fill_value ? fill_value : 0)
383 ]);
384}
385
386export function transpose(matrix: number[][]) {
387 if (!matrix) {

Callers 1

reference.tsFile · 0.85

Calls 1

isOneDimensionalArrayFunction · 0.85

Tested by

no test coverage detected