Closures






function mug(){
  return function shotGlass(){

  }
}





function mug(darkNut){
  return function shotGlass(){
    return darkNut
  }
}





function mug(darkNut){
  return function shotGlass(){
    return darkNut
  }
}

const shotGlass = mug("almond")





function mug(darkNut){
  return function shotGlass(lightNut){
    return [darkNut, lightNut]
  }
}

const shotGlass = mug("almond")





function mug(darkNut){
  return function shotGlass(lightNut){
    return [darkNut, lightNut]
  }
}

const shotGlass = mug("almond")
const nuts = shotGlass("cashew")

// ["almond", "cashew"]
const user = {
    favorites: ["pikachu", "charmander"]
}
const pokemonList = [
    "pikachu", "charmander", "squirtle"
]

pokemonList.filter(pokemon => {
    return user.favorites.includes(pokemon)
})
pokemonList.filter(onlyFavorites)

function onlyFavorites(pokemon){
    return user.favorites.includes(pokemon)
}
pokemonList.filter(pokemon => {
    return user.favorites.includes(pokemon)
})

Uh Oh

function onlyFavorites(user){
    return function(pokemon){
      return user.favorites.includes(pokemon)
    }
}

const onlyUserFavorites = onlyFavorites(user)
pokemonList.filter(onlyUserFavorites)

// ["pikachu", "charmander"]

Mug

Almond

Shot Glass

Cashew

pokemonList.filter(onlyFavorites)

function onlyFavorites(pokemon){
    return user.favorites.includes(pokemon)
}
const onlyFavorites = user => pokemon => user.favorites.includes(pokemon)

pokemonList.filter(onlyFavorites(user)) // ["pikachu", "charmander"]

Closures

By Kyle Coberly