Am i missing something? it says you should not mutate state

Tell us what’s happening:
it says you should initialize state with [0,1,2,3,4,5] which is sure i’m ok here.
second it says you should not mutate state. i checked it with console.log() but test are not passing.

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
      return  state.slice(0, action.index).concat(state.slice(action.index + 1));
    default:
      return state;
  }
};

const removeItem = (index) => {
  return {
    type: 'REMOVE_ITEM',
    index
  }
}

const store = Redux.createStore(immutableReducer);
store.dispatch(removeItem(5));
console.log(store.getState());

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36.

Link to the challenge:

you cant apply slice directly to state.

you have to maybe set a new variable using your state, apply the logic, then use this.setState() inside a function

this.setState({ state:state.slice(0, action.index).concat(state.slice(action.index + 1)) });
gives error. can not read property setState of undefined