How to sum the corners of a matrix in TypeScript

1 Answer

0 votes
function sumMatrixCorners(matrix: number[][]) {
  return matrix[0][0] + 
         matrix[0][matrix[0].length - 1] + 
         matrix[matrix.length - 1][0] + 
         matrix[matrix.length - 1][matrix[0].length - 1];
}
  
const matrix: number[][] = [
  [1, 2, 3, 4],
  [5, 6, 7, 8],
  [9, 3, 2, 0]
];
  
console.log(sumMatrixCorners(matrix));
  
  
      
      
/*
run:
      
14
      
*/

 



answered May 21, 2024 by avibootz

Related questions

1 answer 152 views
1 answer 150 views
1 answer 119 views
119 views asked May 20, 2024 by avibootz
1 answer 90 views
90 views asked May 20, 2024 by avibootz
1 answer 93 views
1 answer 106 views
1 answer 111 views
111 views asked May 19, 2024 by avibootz
...