Created
February 13, 2019 16:39
-
-
Save mohnatus/8d56779314134cf24971f2d0e7a2e2db to your computer and use it in GitHub Desktop.
matrix rows and cols reduce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // свести каждый ряд матрицы к одному значению (например, минимальная высота) | |
| 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