add
add
(n1: number) => (n2: number) => number
Add two numbers together
const add1To = add(1) add1To(3) // is 4
const add1To = add(1) add1To(3) // is 4
const add1To = add(1) add1To(3) // is 4
const add1To = add(1) add1To(3) // is 4
Sometimes we want to add a constant. Below, we're building a spell for our game that heals for five health. Let's test it on our hero Meg.
const heal = update({ health: add(5) }) const hero = { health: 2, name: 'meg' } const healedHero = heal(hero) console.log(healedHero) // is { // health: 7 // name: meg // }
const heal = update({ health: add(5) }) const hero = { health: 2, name: 'meg' } const healedHero = heal(hero) console.log(healedHero) // is { // health: 7 // name: meg // }
const heal = update({ health: add(5) }) const hero = { health: 2, name: 'meg' } const healedHero = heal(hero) console.log(healedHero) // is { // health: 7 // name: meg // }
const heal = update({ health: add(5) }) const hero = { health: 2, name: 'meg' } const healedHero = heal(hero) console.log(healedHero) // is { // health: 7 // name: meg // }