4 ms·
sum(); // TypeError: Cannot read property 'length' of undefined That doesn't mean it's not pure. var arr = [{}, {}, {}]; arr[0].valueOf = arr[1].value
by ajuc 10y ago
sum(); // TypeError: Cannot read property 'length' of undefined
That doesn't mean it's not pure.
var arr = [{}, {}, {}];
arr[0].valueOf = arr[1].valueOf = arr[2].valueOf = Math.random;
sum(arr); // 2.393660612848899
sum(arr); // 2.3418339292845998
sum(arr); // 2.15048094452324
Oh come on. By that logic there are no pure functions in C, because you can play with #define. Definitions are meant to be useful.