Immutable Arrays

Copy an array…

clone = array => [...array]

Add something to the end of an array…

push = array => [...array, thing]

Remove the last item in an array…

pop = array => array.slice(0,1)

…or the first item…

shift = array => array.slice(1)

or an item at a specific index…

delete = i => array => [...array.slice(0,i), ...array.slice(i+1)]

If you are unsure whether a method mutates or not then checkout doesitmutate.xyz

Thank you Luke Jackson.

 
1
Kudos
 
1
Kudos

Now read this

Computer Shoulders

This November I’m learning how to surf. Today was day one. If I’ve learned anything today, it’s that surfing is fantastic for people who spends all day hunched over a computer screen. It’s not the surfing; it’s all the paddling out to... Continue →