(values)
| 7912 | } |
| 7913 | |
| 7914 | function sum(values) { |
| 7915 | var result = 0; |
| 7916 | for (var i = 0, len = values.length; i < len; i++) { |
| 7917 | var num = values[i]; |
| 7918 | if (typeof num !== 'number') { |
| 7919 | if (Array.isArray(num)) { |
| 7920 | // lists of numbers are also allowed, sum them separately |
| 7921 | result = typeof result === 'number' ? [result] : result; |
| 7922 | for (var j = 0, jLen = num.length; j < jLen; j++) { |
| 7923 | var jNum = num[j]; |
| 7924 | if (typeof jNum !== 'number') { |
| 7925 | throw createBuiltInError('_sum'); |
| 7926 | } else if (typeof result[j] === 'undefined') { |
| 7927 | result.push(jNum); |
| 7928 | } else { |
| 7929 | result[j] += jNum; |
| 7930 | } |
| 7931 | } |
| 7932 | } else { // not array/number |
| 7933 | throw createBuiltInError('_sum'); |
| 7934 | } |
| 7935 | } else if (typeof result === 'number') { |
| 7936 | result += num; |
| 7937 | } else { // add number to array |
| 7938 | result[0] += num; |
| 7939 | } |
| 7940 | } |
| 7941 | return result; |
| 7942 | } |
| 7943 | |
| 7944 | // Inside of 'vm' for Node, we need a way to translate a pseudo-error |
| 7945 | // back into a real error once it's out of the VM. |
no test coverage detected