You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
638 B

4 years ago
  1. 'use strict';
  2. var values = require('../helpers/values');
  3. var _require = require('../helpers/is'),
  4. isFunction = _require.isFunction;
  5. module.exports = function sum(key) {
  6. var items = values(this.items);
  7. var total = 0;
  8. if (key === undefined) {
  9. for (var i = 0, length = items.length; i < length; i += 1) {
  10. total += items[i];
  11. }
  12. } else if (isFunction(key)) {
  13. for (var _i = 0, _length = items.length; _i < _length; _i += 1) {
  14. total += key(items[_i]);
  15. }
  16. } else {
  17. for (var _i2 = 0, _length2 = items.length; _i2 < _length2; _i2 += 1) {
  18. total += items[_i2][key];
  19. }
  20. }
  21. return total;
  22. };