Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save davidystephenson/1f139bbb6f78674d6bed788d921e4080 to your computer and use it in GitHub Desktop.

Select an option

Save davidystephenson/1f139bbb6f78674d6bed788d921e4080 to your computer and use it in GitHub Desktop.
function openMine () {
let diamonds = 21
function dig (getDug: (remaining: number) => number) {
const dug = getDug(diamonds)
diamonds -= dug
console.log('diamonds', diamonds)
return dug
}
return dig
}
const digNorth = openMine()
const digSouth = openMine()
function getOne () {
return 1
}
function getTwo () {
return 2
}
function getHalf (remaining: number) {
return remaining / 2
}
digNorth(getOne) // diamonds 20
digSouth(getTwo) // diamonds 19
const dugNorth = digNorth(getHalf)
const dugSouth = digSouth(getHalf)
console.log('dugNorth', dugNorth)
console.log('dugSouth', dugSouth)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment