Created
October 17, 2018 17:44
-
-
Save jepras/1613eb0897769be4f058be532691d689 to your computer and use it in GitHub Desktop.
Use spread operator. Start to slice from beginning until index, then add a slice starting from index + 1 until end.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | |
...state.slice(action.index + 1, state.length) | |
] | |
default: | |
return state; | |
} | |
}; | |
const removeItem = (index) => { | |
return { | |
type: 'REMOVE_ITEM', | |
index | |
} | |
} | |
const store = Redux.createStore(immutableReducer); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment