Created
June 9, 2021 01:09
-
-
Save MeetMartin/364f9e0a7885ce341976af7a65aaee88 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| let state = { | |
| foreground: '#999999', | |
| background: '#FFFFFF'; | |
| }; | |
| const imperativeMakeBackgroundBlack = () => { | |
| state.background = '#000000'; | |
| }; | |
| // directly changes the state object outside of its internal scope | |
| const declarativeMakeBackgroundBlack = state => ({...state, background: '#000000'}); | |
| // takes current state as its input and returns new state with changed value | |
| // without changing the original state | |
| let turtles = ['Galápagos tortoise', 'Greek Tortoise']; | |
| const imperativeAddTurtle = turtle => turtles.push(turtle); | |
| // changes the turtles external array and returns the length of the new array | |
| const declarativeAddTurtle = turtles => turtle => [...turtles, turtle]; | |
| // takes 'array of turtles' and the 'new turtle' as its input. | |
| // It returns new array of turtles without changing the original array |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment