Guest User

Untitled

a guest
Jan 21st, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. /* Create A Reducer
  2. *
  3. * You need to create a reducer called "appReducer" that accepts two arguments:
  4. * - First, an array containing information about ice cream
  5. * - Second, an object with a 'DELETE_FLAVOR' `type` key
  6. * (i.e., the object contains information to delete the flavor from the state)
  7. *
  8. * The action your reducer will receive will look like this:
  9. * { type: 'DELETE_FLAVOR', flavor: 'Vanilla' }
  10. *
  11. * And the initial state will look something like this (as such, refrain
  12. * from passing in default values for any parameters!):
  13. * [{ flavor: 'Chocolate', count: 36 }, { flavor: 'Vanilla', count: 210 }];
  14. */
  15.  
  16. const DELETE_FLAVOR = 'DELETE_FLAVOR';
  17.  
  18. const appReducer = (state, action) =>{
  19. switch(action.type){
  20. case DELETE_FLAVOR:
  21. return state.filter(obj => obj.flavor !== action.flavor);
  22. default:
  23. return state;
  24.  
  25. }
  26. }
  27.  
  28. const test = appReducer(
  29. [
  30. { flavor: 'Chocolate', count: 36 },
  31. { flavor: 'Vanilla', count: 210 }],
  32. { type: 'DELETE_FLAVOR', flavor: 'Vanilla' }
  33. );
  34.  
  35. console.log(test);
Add Comment
Please, Sign In to add comment