-
Notifications
You must be signed in to change notification settings - Fork 2
/
JZ53表示数值的字符串.html
31 lines (27 loc) · 1.02 KB
/
JZ53表示数值的字符串.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
// https://www.nowcoder.com/practice/6f8c901d091949a5837e24bb82a731f2?tpId=13&tqId=11206&rp=1&ru=%2Fta%2Fcoding-interviews&qru=%2Fta%2Fcoding-interviews%2Fquestion-ranking&tab=answerKey
// 请实现一个函数用来判断字符串是否表示数值(包括整数和小数)。
// 例如,字符串"+100","5e2","-123","3.1416"和"-1E-16"都表示数值。
// 但是"12e","1a3.14","1.2.3","+-5"和"12e+4.3"都不是。
function isNumeric(s) {
// write code here
// 或 return !isNaN(str)
return !Number.isNaN(Number(s));
}
// 只有数字 + - . e E
// 科学计算法后面必为整数
// 用正则表达式
let input = '123.45e+6';
let res = true;
</script>
</body>
</html>