昨天看到了道题
["1","2","3"].map(parseInt) => ?
没能理解,今天发现了很好用的DevDocs,查函数查的飞起,终于搞明白了问题:
1、array.map()函数 y = f (x)
The map() method creates a new array with the results of calling a provided function on every element in this array.
Syntax
var new_array = arr.map( callback [ ,thisArg ] )
Parameters
callback : currentValue, index, array;
hisArg ? this : undefined
Return value
A new array with each element being the result of the callback function.
//examples:
var numbers = [1, 5, 10, 15];
var roots = numbers.map(function(x) {
return x * 2;
});
// roots is now [2, 10, 20, 30]
// numbers is still [1, 5, 10, 15]
var numbers = [1, 4, 9];
var roots = numbers.map(Math.sqrt);
// roots is now [1, 2, 3]
// numbers is still [1, 4, 9]
2、parseInt
The parseInt() function parses(解析) a string argument and returns an integer of the specified radix (the base in mathematical numeral systems).
Syntax
parseInt(string, radix);
Parameters
string : 需要解析的字符串,if not a string ,use ToString => string
radix : An integer between 2 and 36
Return value
An integer number parsed from the given string. If the first character cannot be converted to a number, NaN
is returned.
If radix is undefined or 0 (or absent), JavaScript assumes the following:
If the input string begins with "0x" or "0X", radix is 16 (hexadecimal) and the remainder of the string is parsed.
If the input string begins with "0", radix is eight (octal) or 10 (decimal). Exactly which radix is chosen is implementation-dependent. ECMAScript 5 specifies that 10 (decimal) is used, but not all browsers support this yet. For this reason always specify a radix when using parseInt.
If the input string begins with any other value, the radix is 10 (decimal).