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
addSubtract(1)(2)(3); // 1 + 2 - 3 = 0 | |
addSubtract(1)(2)(3)(4)(5)(6); // 1 + 2 - 3 + 4 - 5 + 6 = 5 |
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
setGlobal({ count: 0 }); | |
function reducer(state, action) { | |
switch (action.type) { | |
case 'reset': | |
return { count: 0 }; | |
case 'increment': | |
return { count: state.count + 1 }; | |
case 'decrement': | |
return { count: state.count - 1 }; |
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 initialState = { count: 0 }; | |
function reducer(state, action) { | |
switch (action.type) { | |
case 'reset': | |
return initialState; | |
case 'increment': | |
return { count: state.count + 1 }; | |
case 'decrement': | |
return { count: state.count - 1 }; |
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 MyComponent = () => { | |
const [ global, setGlobal ] = useGlobal(); | |
if (global.x) { | |
return global.x; | |
} | |
return global.y; | |
}; |
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 MyComponent = () => { | |
const [ global, setGlobal ] = useGlobal(); | |
return ( | |
<img | |
alt="Avatar" | |
onClick={() => { | |
const newAvatar = prompt("Enter your avatar URL:"); | |
setGlobal({ | |
avatar: newAvatar | |
}); |
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
import { useGlobal } from 'reactn'; | |
const MyComponent = () => { | |
const [ avatar, setAvatar ] = useGlobal('avatar'); | |
return ( | |
<img | |
alt="Avatar" | |
onClick={() => { | |
const newAvatar = prompt("Enter your avatar URL:"); | |
setAvatar(newAvatar); |
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
import { setGlobal } from 'reactn'; | |
setGlobal({ | |
avatar: 'anonymous.png' | |
}); |
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
import { useState } from 'react'; | |
const MyComponent = () => { | |
const [ avatar, setAvatar ] = useState('anonymous.png'); | |
return ( | |
<img | |
alt="Avatar" | |
onClick={() => { | |
const newAvatar = prompt("Enter your avatar URL:"); | |
setAvatar(newAvatar); |
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 [ value, setValue ] = useState(DEFAULT_VALUE); |
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 quickSort = ( | |
unsortedArray, | |
comparator = defaultComparator | |
) => { | |
// Create a sortable array to return. | |
const sortedArray = [ ...unsortedArray ]; | |
// Recursively sort sub-arrays. | |
const recursiveSort = (start, end) => { |