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
| export default function App() { | |
| const diet = useSelector((state) => state.diet); | |
| const dispatch = useDispatch(); | |
| function handleVegToggle() { | |
| dispatch({ | |
| type: ACTIONS.CHANGE_DIET, | |
| }); | |
| } | |
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
| function useLoadFoodData() { | |
| const [stateAPIStatus, setAPIStatus] = useState('idle'); | |
| const dispatch = useDispatch(); | |
| useEffect(() => { | |
| setAPIStatus('loading'); | |
| loadFoodData() | |
| .then((data) => { | |
| dispatch({ | |
| type: ACTIONS.LOAD_MENU, |
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
| [{"name":"hackerrank_r_admin_base_layout","path":"public/assets/hackerrank_r_admin_base_layout-49646c5f27.js","size":4185,"gzipSize":1728},{"name":"hackerrank_r_advanced_settings","path":"public/assets/hackerrank_r_advanced_settings-e0275897a8.js","size":25301,"gzipSize":7100},{"name":"hackerrank_r_app","path":"public/assets/hackerrank_r_app-d1c2dd3dfc.js","size":105025,"gzipSize":31890},{"name":"hackerrank_r_auth","path":"public/assets/hackerrank_r_auth-aa2a575bfb.js","size":14519,"gzipSize":3894},{"name":"hackerrank_r_billing_settings","path":"public/assets/hackerrank_r_billing_settings-75165607d7.js","size":18635,"gzipSize":6206},{"name":"hackerrank_r_calendar","path":"public/assets/hackerrank_r_calendar-524d5417a3.js","size":9407,"gzipSize":3132},{"name":"hackerrank_r_career_fair_faq","path":"public/assets/hackerrank_r_career_fair_faq-53ecffa0d4.js","size":3500,"gzipSize":1360},{"name":"hackerrank_r_career_fair","path":"public/assets/hackerrank_r_career_fair-cbc7612c28.js","size":36356,"gzipSize":9577},{" |
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
| // request with url as positional arg and options as named args. | |
| fetch('https://google.com', { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| }, | |
| }); | |
| // basic GET requests with just positional args | |
| fetch('https://google.com'); |
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
| function myCustomParseInt({ item, radix } = {}) { | |
| return parseInt(item, radix); | |
| } |
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
| // positional args | |
| function myCustomParseInt(item, radix) { | |
| return parseInt(item, radix); | |
| } | |
| // old implementation of named args | |
| function myCustomParseInt(objArgs) { | |
| return parseInt(objArgs.item, objArgs.radix); | |
| } |
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
| // With positional args we had to add a null in between | |
| function greetPos(firstName, middleName, lastName) {} | |
| greetPos('Aditya', null, 'Agarwal'); | |
| // With named args you just provide firstName & lastName. | |
| function greetNamed({ firstName, middleName, lastName } = {}) {} | |
| greetNamed({ firstName: 'Aditya', lastName 'Agarwal' }); |
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
| const numbers = ['1', '4', '8', '10']; | |
| const result = numbers.map((item, index) => myCustomParseInt({ item, index })); | |
| console.log(result); // [ 1, 4, 8, 10 ] |
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
| // Implementation | |
| function myCustomParseInt(objArgs) { | |
| return parseInt(objArgs.item, objArgs.radix); | |
| } | |
| // Usage | |
| const num = myCustomParseInt({ item: '100', radix: 10 }); |
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
| const numbers = ['1', '4', '8', '10']; | |
| console.log(numbers.map(parseInt)); | |
| // You might think the result would be- | |
| [1, 4, 8, 10] | |
| // Here's the actual output- | |
| [ 1, NaN, NaN, 3 ] |