...
/Tip 15: Create Maps Without Side Effects
Tip 15: Create Maps Without Side Effects
In this tip, you’ll learn how to avoid side effects by creating new maps from an array of pairs.
We'll cover the following...
We'll cover the following...
Copying & mutation in maps
Up to this point, you’ve always worked on a single instance of a map. You’ve either added data or removed data directly from an instance of a Map object.
Working on the instance of a map can lead to a few problems. How do you create copies of a map? How can you make changes without side effects?
Fortunately, you can solve those problems by applying a few principles you’ve learned from arrays and objects.
To start, look at an example that combines the problems of copying and mutations: applying a set of defaults to a map.
Example: Applying defaults to a map
In your pet adoption code, you have filters that users have selected, but ...