Created
June 3, 2016 23:16
-
-
Save joaomilho/d7ef44727196fb6a7f1c4a754a06a538 to your computer and use it in GitHub Desktop.
A calculatorReducer in JS
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 calculatorReducer = (state, { type, payload }) { | |
switch (type) { | |
case 'add': | |
return state + payload | |
case 'subtract': | |
return state - payload | |
case 'multiply': | |
return state * payload | |
case 'divide': | |
return state / payload | |
default: | |
return state | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment