We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9711ab0 commit a359bb2Copy full SHA for a359bb2
Moonjonghoo/stack/String_Calculation.js
@@ -0,0 +1,17 @@
1
+function solution(my_string) {
2
+ const splited = my_string.split(" ");
3
+
4
+ let ans = Number(splited[0]);
5
6
+ splited.forEach((item, index) => {
7
+ if (item === "+") {
8
+ ans += Number(splited[index + 1]);
9
+ }
10
11
+ if (item === "-") {
12
+ ans -= Number(splited[index + 1]);
13
14
+ });
15
16
+ return ans;
17
+}
0 commit comments