这段代码用lodash怎么写

  var CARS = [
      { name: "Ferrari FF", horsepower: 660, dollar_value: 700000, in_stock: true },
      { name: "Spyker C12 Zagato", horsepower: 650, dollar_value: 648000, in_stock: false },
      { name: "Jaguar XKR-S", horsepower: 550, dollar_value: 132000, in_stock: false },
      { name: "Audi R8", horsepower: 525, dollar_value: 114200, in_stock: false },
      { name: "Aston Martin One-77", horsepower: 750, dollar_value: 1850000, in_stock: true },
      { name: "Pagani Huayra", horsepower: 700, dollar_value: 1300000, in_stock: false }
    ];
    
   var _fastestCar = _
      .chain(CARS)
      .sortBy('horsepower')
      .last()
      .property('name')
      .partial((a, b) => a + b, _, 'is the fastest')
      .value()

    console.log(_fastestCar)

这段代码property,partial 用法有问题,怎么用lodash实现链式调用,拿到最快速度的车对象,获取name属性,在后面拼接 is the fastest,最后变成 Aston Martin One-77 is the fastest

阅读 1.8k
2 个回答
_.chain(CARS)
      .sortBy('horsepower')
      .last()
      .get('name')
      .add(' is the fastest')
      .value()
_(CARS).sortBy(o => o.horsepower).takeRight(1).map(item => item.name + ' is the fastest').first();

clipboard.png

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题