DEV Community

Discussion on: Moving Element In An Array From Index To Another

Collapse
 
jalal246 profile image
Jalal 🚀

It works perfectly with tests

github.com/jalal246/move-position/...

Collapse
 
quixomatic profile image
James Freund

I think they just meant that you shouldn't mutate the original array/object directly. Best practice would be to return a new array with the correctly arranged elements within it.

Would be a minor code change, and would be more widely accepted since you should never mutate original data in a black box style function call.

Thread Thread
 
jalal246 profile image
Jalal 🚀 • Edited

It's optional just pass {isMutate: false} and it won't mutate: github.com/jalal246/move-position#....

since you should never mutate original data

It depends. 1-The scale of your data 2-Data mutation frequency 3-Data reference type.