-
Notifications
You must be signed in to change notification settings - Fork 1
/
isNumber.js
33 lines (28 loc) · 1.1 KB
/
isNumber.js
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
// https://stackoverflow.com/questions/20169217/how-to-write-isnumber-in-javascript
var isNumber = function isNumber(value) {
return typeof value === 'number' && isFinite(value);
}
var isNumberObject = function isNumberObject(n) {
return (Object.prototype.toString.apply(n) === '[object Number]');
}
var isCustomNumber = function isCustomNumber(n){
return isNumber(n) || isNumberObject(n);
}
console.log(isCustomNumber(new Number(5)));
console.log(isCustomNumber(new Number(5.2)));
console.log(isCustomNumber(new Number(5.5)));
console.log(isCustomNumber(new Number(-1)));
console.log(isCustomNumber(new Number(-1.5)));
console.log(isCustomNumber(new Number(-0.0)));
console.log(isCustomNumber(new Number(0.0)));
console.log(isCustomNumber(new Number(0)));
console.log(isCustomNumber(new Number(1e5)));
console.log(isCustomNumber(5));
console.log(isCustomNumber(5.2));
console.log(isCustomNumber(5.5));
console.log(isCustomNumber(-1));
console.log(isCustomNumber(-1.5));
console.log(isCustomNumber(-0.0));
console.log(isCustomNumber(0.0));
console.log(isCustomNumber(0));
console.log(isCustomNumber(1e5));