by jfaucett · 11y ago · 0 comments
Couldnt agree more, variables are just clutter you have to keep mental track of, and working with series of transformations is much easier (for me at least) to process. I would be interested to know if its like this for all developers, perhaps not, since I know some that are also opposed to recursion.
but for me this:
sum([]) = 0.
sum([H|T]) = H + sum(T).
is much easier to understand than: function sum(ary) {
var i = ary.length,
res;
while(--i) {
res += ary[i];
}
return res;
} function sum(array) {
return array.reduce((a, b) => a + b);
}
With a loop: function sum(array) {
let acc = 0;
for(let val of array) {
acc += val;
}
return acc;
} sum = (values) ->
values.reduce (result, x) -> result + x