2👍
✅
Use sumBy
instead of sum
:
This method is like
_.sum
except that it accepts iteratee which is
invoked for each element in array to generate the value to be summed.
The iteratee is invoked with one argument: (value).
👤CD..
1👍
Are you set on _.sum
and then mapping? Because you can simply do:
additup() { return _.sumBy(this.todos, 'time') }
Or with ES6 you could get even shorter by:
additup = () => _.sumBy(this.todos, 'time')
This is actually _.sumBy main use-case.
Source:stackexchange.com