Is this the intended solution for solving this challenge using the spread operator?
How is the line return [...state.slice(0,action.index), ...state.slice(action.index+1, state.length)];
evaluated? I was confused at first because I read it left to right. So ...state would “spread out” the elements of state, and thus the subsequent .slice(0, action.index) should not work (because .slice() needs to be called on an array), right? But apparently the solution does work, so I’m guessing state.slice(0,action.index) is evaluated first before ... is applied? There’s some sort of order of precedence with the operators, and it’s not just evaluated left to right?
I guess I should include the link to this solution:
I see, so going off of your example animals.slice(2) is evaluated to an array before ... is applied. I guess my confusion was due to the fact that I thought expressions were always evaluated left to right, and so I thought ...animals would be evaluated first.