The topic describes how to modify the invocation of parseint in the JS code so that it is entered through all test case Example 1
' 12 '
Output
12
Example 2 input replication
' 12px '
Output replication
12
Example 3 input
' 0x12 '
Output
0
function Parse2int (num) { var type = typeof num; if (type = = = "Number") { if (num% 1 = = = 0) { return num; } else { return num-num%1;} } else if ( Type = = = "string") { var s = "", N0 = "0". charCodeAt (0), N9 = "9". charCodeAt (0); for (var i = 0; i < num.length; i++) { var c = num.charcodeat (i); if (N0 <= c && C <= N9) { s + = Num.charat (i); } else {break ; } } function S2i (s) { var n = 0, n0 = "0". charCodeAt (0); for (var i = 0; i < s.length; i++) { n = 10*n + (s.charcodeat (i)-n0); } return n; } return s2i (s); } return NaN;}
* Process Control
To implement the Fizzbuzz function, the relationship between the parameter num and the return value is as follows:
1. If num can be divisible by 3 and 5 at the same time, return the string Fizzbuzz
2. If num can be divisible by 3, return the string fizz
3. If num can be divisible by 5, return string buzz
4. Returns False if the argument is empty or is not of type number
5, the rest of the case, the return parameter num
Input:15 Output:fizzbuzz
function Fizzbuzz (num) { if (!num) {return! 1;} if (typeof num = = = "Number") { var a = num%3===0, B = num%5==0; Return a&&b? "Fizzbuzz": A? "Fizz": B? "Buzz": num; } return! 1;}
JavaScript encoding specification-correct use of parseint