Created
June 6, 2020 12:03
-
-
Save ispoljari/7957818eeb3639a4f16a45f91759eee8 to your computer and use it in GitHub Desktop.
Example of pure functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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