Tell us what’s happening:
Following is my code using splice
it is not passing, but why? I checked the hint section and it is using slice. Isn’t my code doing the same as the slice code?
I didn’t understand the hint code as it is using slice
twice
return [
...state.slice(0, action.index),
...state.slice(action.index + 1, state.length)
];
Why? It doesn’t say in question from where we have to start.
Your code so far
const immutableReducer = (state = [0,1,2,3,4,5], action) => {
switch(action.type) {
case 'REMOVE_ITEM':
// Don't mutate state here or the tests will fail
const copiedArr = [...state].splice(action.index, 1);
console.log(copiedArr, "copied arr");
return copiedArr
default:
return state;
}
};
const removeItem = (index) => {
return {
type: 'REMOVE_ITEM',
index
}
}
const store = Redux.createStore(immutableReducer);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36
Challenge: Redux - Remove an Item from an Array
Link to the challenge: