HackerRank Diagonal Difference JavaScript Solution

Megan
Mar 17, 2022

For this problem, you are given a square matrix and you need to find the absolute difference between the sums of its diagonals.

Example.
My solution.

First, you need to initialize the sum of each diagonal, d1 and d2.

Then, loop through the array and find the sum of the first diagonal. Repeat with a new loop for the second diagonal sum.

Finally, return the absolute value of the first sum minus the second.

--

--