Skip to content

Instantly share code, notes, and snippets.

@keshihoriuchi
Last active July 30, 2022 08:05
Show Gist options
  • Save keshihoriuchi/f26bba4976d50bb8a8552aea51ee8dcd to your computer and use it in GitHub Desktop.
Save keshihoriuchi/f26bba4976d50bb8a8552aea51ee8dcd to your computer and use it in GitHub Desktop.
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