我在用Lodash..。
coffee> _ = require("lodash")
[stuff deleted]
这个表达式给出了正确的答案..。
coffee> _.map("7-9".split("-"), (x)->parseInt(x))
[ 7, 9 ]
但是,对于数组中的最后一个结果,这一项给出的结果略有不同:
coffee> _.map("7-9".split("-"), parseInt)
[ 7, NaN ]
coffee>
为什么答案不同?当然,(x)->paresInt(x)的行为应该和parseInt一样。
发布于 2016-02-08 20:21:10
用这个代替:require('lodash').map("7-9".split("-"), Number)
;)
Objects/parseInt,意思是用两个参数调用parseInt,第二个参数必须是基数,现在是1 (parseInt(9,1))。
您还可以使用https://lodash.com/docs#ary _.map("7-9".split("-"), _.ary(parseInt, 1));
https://stackoverflow.com/questions/32497918
复制相似问题