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.
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
.
Implement the function:
function findCheckSum(matrix){
//your code here
}