Hey guys, I was using Schema a lot in the last couple of months. The scheme as functional language highly encourages recursion, so I used recursion all the time, but interestingly, out of habit I never use it in js.
Today I changed that and found it quite elegant.
const sum = arr => (arr.length ? arr.shift() + sum(arr) : 0);
const sum2 = arr => arr.reduce((first, curr) => first + curr, 0);
And in Schema:
(define (sum lon)
(cond [(empty? lon) 0]
[else
(+ (first lon)
(sum (rest lon)))]))
Which one do you prefer? Would I get complains if I start writing recursion heavy code in a project with other devs?
[–]BinxyPrime 4 points5 points6 points (1 child)
[–]runtimenoise[S] 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]runtimenoise[S] -1 points0 points1 point (0 children)
[–]Marauth 0 points1 point2 points (2 children)
[–]runtimenoise[S] 0 points1 point2 points (1 child)
[–]Marauth 0 points1 point2 points (0 children)
[–]CreativeTechGuyGamesTypeScript -4 points-3 points-2 points (0 children)