我有使用2 lodash方法过滤器和地图的代码
const filtered_holidays = filter(holidays, day => day.holiday === 1);
const type_calendar_holidays = map(filtered_holidays, 'day');
如何在lodash中用1个字符串重写它?像这样的东西
holidays.filter().map()....
const filtered_holidays = filter(holidays, day => day.holiday === 1);
const type_calendar_holidays = map(filtered_holidays, 'day');
答案 0 :(得分:1)
您可以使用地图包装过滤器:
const result = map(filter(holidays, day => day.holiday === 1),'day');
您可以使用sequence(需要导入整个lodash包装):
const result = _(holidays).filter(day => day.holiday === 1).map('day').value();
您可以将_.flow()
与_.flowRight()
一起使用lodash/fp(或也称为_.partialRight()
):
const result = flow(filter(day => day.holiday === 1), map('day'))(holidays)
注意:flow和flowRight也可以在常规lodash中使用,但是由于参数的顺序是向后的,并且该函数不会自动使用,因此您需要使用{{3}}。
const result = flow(partialRight(filter, day => day.holiday === 1), partialRight(map, 'day'))(holidays)
在这种情况下,最简单的解决方案是使用香草js链接:
const result= holidays.filter(day => day.holiday === 1).map(o => o.day);
答案 1 :(得分:0)
只将过滤器放进去吗?
const type_calendar_holidays = map(filter(holidays, day => day.holiday === 1), 'day');
答案 2 :(得分:0)
在香草JS中,您可以像这样使用reduce
:
holidays.reduce((r, { day, holiday }) => holiday === 1 ? r.concat(day) : r, [])
答案 3 :(得分:0)
只需嵌套Rotate
:
transform.localRotation = q2 * transform.localRotation