Last active
December 6, 2025 08:12
-
-
Save sprzybylski/4eff4a7b71276ffb17f8229130ba85b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const data = [ | |
| "123 328 51 64 ", | |
| " 45 64 387 23 ", | |
| " 6 98 215 314", | |
| "* + * + ", | |
| ]; | |
| const len = data.length; | |
| let total = 0; | |
| let subTotal = 0; | |
| let operator = data[len - 1][0]; | |
| for (let col = 0; col < data[0].length; col++) { | |
| const number = Number( | |
| data.slice(0, len - 1).reduce((acc, row) => { | |
| const char = row[col]; | |
| return acc + char; | |
| }, ""), | |
| ); | |
| if (number !== 0) { | |
| if (operator === "+") { | |
| subTotal += number; | |
| } else { | |
| if (subTotal === 0) { | |
| subTotal = number; | |
| } else { | |
| subTotal *= number; | |
| } | |
| } | |
| } | |
| if (number === 0) { | |
| total += subTotal; | |
| operator = data[len - 1][col + 1]; | |
| subTotal = 0; | |
| } | |
| } | |
| console.log(total + subTotal); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment