This is a playground
to test code. It runs a full Node.js
environment and already has all of npm
’s 1,000,000+ packages pre-installed, including match-ish
with all npm
packages installed. Try it out:
const { match } = require("match-ish");
const factorial = match()
.with('0', () => 1)
.with('n', ({n}) => n * factorial(n - 1))
.end();
console.log('0', factorial(0))
console.log('4', factorial(4))
console.log('10', factorial(10))
const howMany = match()
.with('[]', () => 'empty')
.with('[_]', () => 'one')
.with('[_, _]', () => 'two')
.with('[_, _, ...]', () => 'more than two')
.else(() => 'it is not a list')
.end();
console.log(howMany([]))
console.log(howMany([ 1 ]))
console.log(howMany([ 1, 2 ]))
console.log(howMany([ 1, 2, 3 ]))
console.log(howMany('?'))
This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.