我有这个负值数组:
["-117.911732", "-112.0756724", "-71.0595678", "-78.8783689", "-114.0833", "-78.6390779", "-87.6244212", "-104.9847034", "-83.0007065", "-96.7968994", "-83.0567375", "-113.5000", "-80.1936589", "-118.2427266", "-93.1015026", "-73.5833", "-86.78086153", "-74.1723667", "-73.9865812", "-73.9865812", "-75.7000", "-75.163789", "-79.9900861", "-121.8831349", "-90.1978889", "-82.458444", "-79.4167", "-123.1333", "-77.0366456", "-97.1667"]
Lodash的_.min函数返回-104.9847034
而不是-123.1333
,这显然是错误的?我错过了什么?
以下是正在运行的示例:http://codepen.io/neptune01/pen/XMOeVM
答案 0 :(得分:1)
您有字符串数组,因此您需要先使用if let title = annotation_point.title, title == "POA" {
// Rest of the code goes here...
}
将字符串转换为数字。
_.map

var arr = ["-117.911732", "-112.0756724", "-71.0595678", "-78.8783689", "-114.0833", "-78.6390779", "-87.6244212", "-104.9847034", "-83.0007065", "-96.7968994", "-83.0567375", "-113.5000", "-80.1936589", "-118.2427266", "-93.1015026", "-73.5833", "-86.78086153", "-74.1723667", "-73.9865812", "-73.9865812", "-75.7000", "-75.163789", "-79.9900861", "-121.8831349", "-90.1978889", "-82.458444", "-79.4167", "-123.1333", "-77.0366456", "-97.1667"];
console.log(_.min(_.map(arr, Number)))