-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalgorithm22.js
More file actions
37 lines (35 loc) · 799 Bytes
/
Copy pathalgorithm22.js
File metadata and controls
37 lines (35 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function solution(s) {
var answer = [];
let matching = new Map([
['zero', 0],
['one', 1],
['two', 2],
['three', 3],
['four', 4],
['five', 5],
['six', 6],
['seven', 7],
['eight', 8],
['nine', 9],
])
let str_list = []
let num_list = []
let temp = []
let splited = s.split("")
for(let i=0; i<splited.length; i++){
if(matching.has(temp)){
answer += matching.get(temp)
temp = []
}
if(isNaN(splited[i])){
temp += splited[i]
} else {
answer += splited[i]
}
}
if(matching.has(temp)){
answer += matching.get(temp)
temp = []
}
return Number(answer);
}