Skip to content

Instantly share code, notes, and snippets.

@thuyanduong
Last active January 6, 2021 03:31
Show Gist options
  • Save thuyanduong/24fea0813de4181e8f543c46b62e7b4d to your computer and use it in GitHub Desktop.
Save thuyanduong/24fea0813de4181e8f543c46b62e7b4d to your computer and use it in GitHub Desktop.

Matrix Checksum

Problem Statement

You are given a matrix (an array of arrays) which consists of rows of seemingly-random numbers. We need you to determine the matrix's checksum, which is calculated as followed:

For each row, determine the difference between the largest value and the smallest value; the checksum is the sum of all of these differences.

Example

Here's an example of a 3-by-3 matrix:

let data = [
  [3, 2, 8], 
  [0, 1, 10],
  [12, 4, 7] 
]
  • The first row's largest and smallest values are 2 and 8, their difference is 6.
  • The second row's largest and smallest values are 0 and 10, their difference is 10.
  • The third row's difference is 8.

In this example, the matrix's checksum would be 6 + 10 + 8 = 24.

Challenge

Implement the function:

function findCheckSum(matrix){
  //your code here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment