Skip to content

Commit a359bb2

Browse files
committed
String_Calculation / 기초
1 parent 9711ab0 commit a359bb2

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)