Sign Up for Free

RunKit +

Try any Node.js package right in your browser

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.

match-ish v2.0.0

The pattern matching library for javascript

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free