4 ms·
Trivia: assuming the input to `sum` below is guaranteed to always be a non-trickery array of numbers, so it always returns the same result for the same input, i
by nicolast 10y ago
Trivia: assuming the input to `sum` below is guaranteed to always be a non-trickery array of numbers, so it always returns the same result for the same input, is the function 'pure'?
var x = 0;
function sum(arr) {
x += 1;
return arr.reduce(function(a, b) { return a + b; }, 0);
}
- eyelidlessness 10y agoI don't understand how this is ambiguous. `sum` is changing state outside its scope (a side-effect). There is no definition of "pure" I'm aware of that would include this implementation.