revision diagonal sums

Run Settings
LanguageJavaScript
Language Version
Run Command
//also use arr.reverse function processData(input) { let arr = input.split("\n"); let new_arr = [] let n = Number(arr[0]) let sum1 = 0 let sum2 = 0 arr.shift() arr.forEach(element => new_arr.push(element.split(" ").map(Number))); for (let i = 0; i < new_arr.length; i++) { for (let j = 0; j < new_arr[i].length; j++) { if (i==j) { sum1 += new_arr[i][j] } if(i+j == new_arr[i].length -1 ){ sum2 += new_arr[i][j] } } } console.log(Math.abs(sum1 - sum2)); console.log(new_arr); } process.stdin.resume(); process.stdin.setEncoding("ascii"); _input = ""; process.stdin.on("data", function (input) { _input += input; }); process.stdin.on("end", function () { processData(_input); });
Editor Settings
Theme
Key bindings
Full width
Lines