Redux : Remove an Item from an Array challenge help

Redux : Remove an Item from an Array challenge help


Tell us what’s happening:
Im not sure why this is not passing the test. Am I not allowed to use filter() on this challenge?
any feedback will be appreciated.

Your code so far

const immutableReducer = (state = [0,1,2,3,4,5], action) => {
  switch(action.type) {
    case 'REMOVE_ITEM':
      const newState = state.filter( val => val !== action.index );
      return newState;
      return state;

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

const store = Redux.createStore(immutableReducer);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36.

Link to the challenge:


Thank you for the hint .


Your code must delete newState[action.index],but not a number.

I cant think up better, but you may finish the test with it. How can i do it with slice or concat methods?

let newState = [...state];
newState.splice(action.index, 1);
return newState;


This is because you are not getting the value you think you are when using filter

// val is the actual item in the index
const newState = state.filter(val => val !== action.index );

The filter callback has a few more parameters that you could make use of. Take a look at the screenshot from mdn below


As JM-Mendez mentioned your filter function is wrong. Filter method works for “value” filtering not index.
To filter the array by index you have to use:

return state.filter( item=> item != state[action.index]  )


This was the slice/concat method.
return state.slice(0, action.index).concat(state.slice(action.index + 1, state.length));

but yes if you look at the link shared by JM-Mendez you can use the filter method.


Your solution is way more consice than mine.
My original solution state.slice(0,action.index).concat(state.slice(action.index+1)).
Your solution corrected state.filter((v,i)=>i!=action.index)