SKGreyHound

Untitled

Jan 18th, 2021
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. function magicMatrices(input) {
  2.  
  3. let rowSums = input.map(el => el.reduce((a, b) => a + b));
  4.  
  5. let colToRow = input.map((row, i, arr) => arr[i].map((col, y) => arr[y][i]));
  6. let colSums = colToRow.map(ele => ele.reduce((a,b) => a + b));
  7.  
  8. return rowSums.concat(colSums).every((el, i, arr) => el === arr[0]);
  9.  
  10. // let rowSums = [];
  11. // let colSums = [];
  12. // for (let i = 0; i < input.length; i++) {
  13. // let row = input[i];
  14. // let sum = row.reduce((a,b) => a + b)
  15. // rowSums.push(sum)
  16.  
  17. // let newRow = [];
  18. // for (let y = 0; y < input.length; y++) {
  19. // newRow.push(input[y][i]);
  20. // }
  21. // sum = newRow.reduce((a,b) => a + b)
  22. // colSums.push(sum)
  23. // }
  24. //return rowSums.concat(colSums).every((el, i, arr) => el === arr[0]);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment