Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function magicMatrices(input) {
- let rowSums = input.map(el => el.reduce((a, b) => a + b));
- let colToRow = input.map((row, i, arr) => arr[i].map((col, y) => arr[y][i]));
- let colSums = colToRow.map(ele => ele.reduce((a,b) => a + b));
- return rowSums.concat(colSums).every((el, i, arr) => el === arr[0]);
- // let rowSums = [];
- // let colSums = [];
- // for (let i = 0; i < input.length; i++) {
- // let row = input[i];
- // let sum = row.reduce((a,b) => a + b)
- // rowSums.push(sum)
- // let newRow = [];
- // for (let y = 0; y < input.length; y++) {
- // newRow.push(input[y][i]);
- // }
- // sum = newRow.reduce((a,b) => a + b)
- // colSums.push(sum)
- // }
- //return rowSums.concat(colSums).every((el, i, arr) => el === arr[0]);
- }
Advertisement
Add Comment
Please, Sign In to add comment