Diagonal Difference

  • + 2 comments
    let primary = 0;
    let secondary = 0;
    let count = 0;
    for(let i=0;i < arr.length;++i){
         primary += arr[i][count];
         secondary += arr[i][(arr.length-1)-count];
         ++count;          
    }
    return Math.abs(primary-secondary);