The code dosent work

Tell us what’s happening:
I think the code is accurate, I can’t find the mistake if anyone can help… please do

Your code so far


const immutableReducer = (state = [0,1,2,3,4,5], action) => {
switch(action.type) {
  case 'REMOVE_ITEM':
    let newarr=state.slice(0,action.index).concat(state.slice(action.index,state.length));
    return newarr;
    // don't mutate state here or the tests will fail
  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 (X11; Ubuntu; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0.

Challenge: Remove an Item from an Array

Link to the challenge:

Try logging it out.

const state = [0, 1, 2, 3, 4, 5];
const index = 3;

console.log(state.slice(0, index)); // [ 0, 1, 2 ]
console.log(state.slice(index, state.length)); // [ 3, 4, 5 ]

console.log(state.slice(0, index).concat(state.slice(index, state.length))); // [ 0, 1, 2, 3, 4, 5 ]

Think about where the second slice index should start from.

1 Like

Hey,
Looks like you’re not removing anything, test you removal code with some array :wink:

1 Like

I get it now, :sweat_smile: :sweat_smile: :sweat_smile: :sweat_smile: thank you so much :sweat_smile: :sweat_smile: @lasjorg and @Annestezia