You are viewing a single comment's thread. Return to all comments →
function diagonalDifference(arr: number[][]): number { const {a, b} = arr.reduce((acc, item, idx, arr) => { acc.a += item[idx] acc.b += item[arr.length - idx - 1] return acc }, {a: 0, b: 0})
return Math.abs(a - b) }
Seems like cookies are disabled on this browser, please enable them to open this website
Diagonal Difference
You are viewing a single comment's thread. Return to all comments →
function diagonalDifference(arr: number[][]): number { const {a, b} = arr.reduce((acc, item, idx, arr) => { acc.a += item[idx] acc.b += item[arr.length - idx - 1] return acc }, {a: 0, b: 0})
return Math.abs(a - b) }