Skip to content

Instantly share code, notes, and snippets.

@mohnatus
Created February 13, 2019 16:39
Show Gist options
  • Select an option

  • Save mohnatus/8d56779314134cf24971f2d0e7a2e2db to your computer and use it in GitHub Desktop.

Select an option

Save mohnatus/8d56779314134cf24971f2d0e7a2e2db to your computer and use it in GitHub Desktop.
matrix rows and cols reduce
// свести каждый ряд матрицы к одному значению (например, минимальная высота)
function rowsCombine(rows) {
return rows.map(row => {
return row.reduce((combine, currentCell) => combine + currentCell, 0);
});
}
// свести каждую колонку матрицы к одному значению (например, минимальная ширина)
function colsCombine(rows) {
return rows[0].map((_, i) => {
return rows.reduce((combine, currentRow) => {
return combine + currentRow[i];
}, 0);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment