Creating persistent data structures
If you want to change something in a data structure and you just go and change it, your code will be full of side effects. On the other hand, copying complete structures every time is a waste of time and space. There’s a middle ground to this that has to do with persistent data structures, which, if handled correctly, let you apply changes while creating new structures efficiently.
Given that there are many possible data structures you could work with, let’s just take a look at a few examples:
- Working with lists, one of the simplest data structures
- Working with objects, a very common necessity in JavaScript programs
- Dealing with arrays, which will prove to be harder to work with
Let’s get started!
Working with lists
Let’s consider a simple procedure – suppose you have a list and want to add a new element to it. How would you do this? Here, we can assume that each node is a NodeList...