Skip to content

Instantly share code, notes, and snippets.

@ispoljari
Created June 6, 2020 12:03
Show Gist options
  • Select an option

  • Save ispoljari/7957818eeb3639a4f16a45f91759eee8 to your computer and use it in GitHub Desktop.

Select an option

Save ispoljari/7957818eeb3639a4f16a45f91759eee8 to your computer and use it in GitHub Desktop.
Example of pure functions
const planets = ['earth', 'mercury', 'venus', 'mars', 'jupiter'];
const slicedPlanets = planets.slice(2,4);
const inventory = {
cars: [], // example types
boats: [], // example types
trains: [] // example types
};
const removeVehicleTypeFromInventory = (type, inventory) => {
if (type in inventory) {
const copiedInventory = {…inventory};
delete copiedInventory[type];
return copiedInventory;
}
return inventory;
};
const updatedInventory = removeVehicleTypeFromInventory('cars', inventory);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment