diferença diagonal em matrizes 2D JavaScript
function diagonalDifference(arr) {
let leftToRight=[], rightToleft = []
arr.forEach((ar, index)=>{
leftToRight.push(ar[0+index])
rightToleft.push(ar[ar.length - 1 - index])
})
const leftDiagnolSum = leftToRight.reduce((acc, val)=>acc+val)
const rightDiagnolSum = rightToleft.reduce((acc, val)=>acc+val)
return Math.abs(leftDiagnolSum - rightDiagnolSum)
}
Husnain Syed