Created
June 29, 2017 14:45
-
-
Save edorivai/727bc329c51d0d50200a926ce6cfe765 to your computer and use it in GitHub Desktop.
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
function reducer(state, action) { | |
switch (action.type) { | |
case UPDATE_VOTES: | |
const updateVotesList = state.polls.map((poll, ind) => { | |
if (ind === action.question) { | |
return poll.answers.map((ans, index) => | |
index === action.index | |
? { ...ans, votes: ans.votes + action.votes } | |
: ans; | |
); | |
} else { | |
return { polls: { ...state.polls } }; | |
} | |
}); | |
return { | |
...state, | |
polls: updateVotesList, | |
}; | |
default: | |
return state; | |
} |
Author
edorivai
commented
Jun 29, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment