Redux - Remove an Item from an Array

Tell us what’s happening:
Describe your issue in detail here.
Regarding Solution Two, why is an underscore used for the first parameter for .filter? What does it represent?
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.filter((_,index) => index !== action.index)
    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; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36

Challenge: Redux - Remove an Item from an Array

Link to the challenge:

An underscore is the conventional variable name for an unused variable.

Oh I see now, usually I just put a letter there so it threw me off a bit. Thank you

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.