X, which starts at 0, and just four commands:
- ++X and X++ add 1 to X;
- --X and X-- subtract 1 from X.
A program is an array of strings commands, run in order. Return the value of X once the whole program has run.commands=['X++', '--X', 'X--', 'X--'] → -2
0 → 1 → 0 → -1 → -2.
commands=['++X', '++X', 'X++'] → 3
Three increments in a row: 0 → 1 → 2 → 3.
commands=['X--'] → -1
commands.length ≤ 100"++X", "X++", "--X", "X--"commands=['X++', '--X', 'X--', 'X--']
-2
Run checks the first 3 tests in your browser. Submit checks all 91 tests on the server, hidden ones included.