Last active
October 23, 2020 08:55
-
-
Save kasajian/a4fc4d80c364f99ececce1fb8a08fabb to your computer and use it in GitHub Desktop.
recursive fatorial using y-combinator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var factorial = (f => { | |
return y => { | |
return f(y, f); | |
}; | |
})((num, f) => { | |
return (num => { | |
if (num < 0) { | |
return -1; | |
} else if (num === 0) { | |
return 1; | |
} else { | |
return (num * f(num - 1, f)); | |
} | |
})(num); | |
}); | |
console.log(factorial(8)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment