Thanks Mike for pointing out the potential costly operation of shift -- I read somewhere that also compared shift with push and pop, but your explanation makes more sense to me. And yes, using splice first and adding the specific items to the array via spread operator does look more efficient. Really appreciate your help! :)
Thanks Mike for pointing out the potential costly operation of
shift
-- I read somewhere that also comparedshift
withpush
andpop
, but your explanation makes more sense to me. And yes, usingsplice
first and adding the specific items to the array via spread operator does look more efficient. Really appreciate your help! :)Yeah we can do it without spread - but now it looks nicer in ES6 :)