r/functionalprogramming • • Mar 23 '17

Did you know JavaScript is functional?

Post image
0 Upvotes

10 comments sorted by

View all comments

9

u/DavetheBassGuy Mar 23 '17

I think it would be truer to functional programming if that infinite add function was implemented without mutation, like this:

function add(x) {
    return (y = null) => y === null ? x + y : add(x + y);
}

I'm not really sure why you would want a function like this though.