-
Notifications
You must be signed in to change notification settings - Fork 0
/
3-3. 숫자만 추출.html
38 lines (33 loc) · 1.06 KB
/
3-3. 숫자만 추출.html
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
38
<html>
<head>
<meta charset="UTF-8">
<title>출력결과</title>
</head>
<body>
<script>
function solution (str) {
// 정규식 사용법
// let answer = str.replace(/[^0-9]/g, '');
// return parseInt(answer);
// 아스키코드 사용법
// let answer = ''
// for (let i = 0; i < str.length; i++) {
// if (str[i].charCodeAt() >= 48 && str[i].charCodeAt() <= 57) {
// answer += str[i]
// }
// }
// return parseInt(answer);
// isNaN 사용법
let answer = "";
for (let x of str) {
if (!isNaN(x)) {
answer += x;
}
}
return parseInt(answer);
};
let str="g0en2T0s8eSoft";
console.log(solution(str));
</script>
</body>
</html>