function solution(s) {
var answer = 0;
var numMap = new Map([
['zero', '0'],
['one','1'],
['two','2'],
['three','3'],
['four','4'],
['five','5'],
['six','6'],
['seven','7'],
['eight','8'],
['nine','9']
]);
for(e of numMap)
{
if (s.includes(e[0]))
{
var reg = new RegExp(`${e[0]}`,'g');
// ์ ๊ท์์ฌ์ฉํ๋๋ฒ ์์๋๊ธฐ!
s = s.replace(reg, e[1]);
}
}
s= parseInt(s);
return s;
}
'๐ฏ CodingTest > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Programmers] (Javascript) ํฌ๋ ์ธ ์ธํ๋ฝ๊ธฐ (0) | 2022.04.21 |
---|---|
[Programmers] (Javascript) ํคํจ๋ ๋๋ฅด๊ธฐ (0) | 2022.04.21 |
[Programmers] (Javascript) ์ ๊ท์์ด๋ ์ถ์ฒ (0) | 2022.04.21 |
[Programmers] (Javascript) ๋ก๋์ ์ต๊ณ ์์์ ์ต์ ์์ (0) | 2022.04.21 |
[Programmers] (Javascript) ์ ๊ณ ๊ฒฐ๊ณผ ๋ฐ๊ธฐ (0) | 2022.04.21 |