Skip to content

Instantly share code, notes, and snippets.

@FGRibreau
Created December 29, 2015 09:58
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 FGRibreau/6263801408d701a37147 to your computer and use it in GitHub Desktop.
Save FGRibreau/6263801408d701a37147 to your computer and use it in GitHub Desktop.
match-when - Pattern matching for modern JavaScript - https://github.com/FGRibreau/match-when
const {match, when} = require('match-when');
function fact(n){
return match({
[when(0)]: 1,
[when()]: (n) => n * fact(n-1)
})(n);
}
fact(10); // 3628800
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment