Skip to content

Instantly share code, notes, and snippets.

@xiaoyunyang
Last active January 25, 2018 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xiaoyunyang/a41b3316ca2eaa33eaa58d8ab00c01d4 to your computer and use it in GitHub Desktop.
Save xiaoyunyang/a41b3316ca2eaa33eaa58d8ab00c01d4 to your computer and use it in GitHub Desktop.
Closure With Recursion
var incrementUntil = function(max) {
var inc = function(num) {
if(num >= max) return num
return inc(num+1)
}
return (num) => inc(num)
}
incrementUntil(4)(1) //> 4
incrementUntil(8)(3) //> 8
var num = 1
incrementUntil(8)(num) //> 8
num //> 1 .... Good! Our function is pure!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment