Last active
July 30, 2022 08:05
-
-
Save keshihoriuchi/f26bba4976d50bb8a8552aea51ee8dcd to your computer and use it in GitHub Desktop.
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
const z = (f) => { | |
const g = (x) => { | |
return f((v) => { | |
const xx = x(x); | |
return xx(v); | |
}); | |
}; | |
return g(g); | |
}; | |
const fact = z((fact1) => { | |
return (x) => { | |
if (x === 0) { | |
return 1; | |
} else { | |
return x * fact1(x - 1); | |
} | |
}; | |
}); | |
console.log(fact(5)); // 120 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment