Skip to content

Commit 9697257

Browse files
committed
Final Value of Variable After Performing Operations 🐛
1 parent 1ea6c20 commit 9697257

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
function finalValueAfterOperations(operations) {
3+
let X = 0;
4+
5+
for (let op of operations) {
6+
if (op.includes("++")) {
7+
X += 1;
8+
} else {
9+
X -= 1;
10+
}
11+
}
12+
13+
return X;
14+
}
15+
16+
17+
console.log(finalValueAfterOperations(["--X", "X++", "X++"]));
18+
19+
20+
console.log(finalValueAfterOperations(["++X", "++X", "X++"]));
21+
22+
23+
console.log(finalValueAfterOperations(["X++", "++X", "--X", "X--"]));

valid_palindrome.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)