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.

20 lines
374 B

1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. export default function(values, valueof) {
  2. var n = values.length,
  3. i = -1,
  4. value,
  5. sum = 0;
  6. if (valueof == null) {
  7. while (++i < n) {
  8. if (value = +values[i]) sum += value; // Note: zero and null are equivalent.
  9. }
  10. }
  11. else {
  12. while (++i < n) {
  13. if (value = +valueof(values[i], i, values)) sum += value;
  14. }
  15. }
  16. return sum;
  17. }