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
/* | |
Made by Elly Loel - https://ellyloel.com/ | |
With inspiration from: | |
- Josh W Comeau - https://courses.joshwcomeau.com/css-for-js/treasure-trove/010-global-styles/ | |
- Andy Bell - https://piccalil.li/blog/a-modern-css-reset/ | |
- Adam Argyle - https://unpkg.com/open-props@1.3.16/normalize.min.css / https://codepen.io/argyleink/pen/KKvRORE | |
Notes: | |
- `:where()` is used to lower specificity for easy overriding. | |
*/ |
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 error_handler = (property) => { | |
throw new Error(`Error: ${property} is required!`); | |
} | |
const monitor_roads = (car=error_handler('Car'), speed=error_handler('Speed')) => { | |
console.log(`Your ${car} was going at a speed of ${speed}mph.`); | |
} | |
monitor_roads('Ferrari', 240); // Your Ferrari was going at a speed of 240mph. | |
monitor_roads('Ferrari'); // Error: Speed is required! |
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
/* | |
# Coding exercise | |
Implement the array reduce function (including tests) | |
var arr1 = [1,2,3,4]; | |
arr1.reduce((acc, value) => acc + value, 0); // 10 | |
Extension: avoid using loops (use recursion) | |
*/ |
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
/* | |
You have 2 different applications running in the webpage, one with the cart count and another is a list of products. When you add click on "Add to cart" in the project, the cart count needs to get updated. | |
Implement a eventBus / pub/Sub solution to allow communication between the two applications. | |
Write tests to cover common use cases. | |
*/ | |
const EventBus = () => { | |
const listeners = {} |
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
// promise error handling | |
function fetchAndUpdatePosts() { | |
fetchPosts() | |
.then((posts) => { | |
updatePosts(posts) | |
.catch((err) => { | |
console.log('error in updating posts'); | |
}); | |
}) | |
.catch(() => { |
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 caughtFunction = () => { | |
try { | |
blarg; | |
} catch (e) { | |
throw new Error('Ghaaa!'); | |
} | |
} | |
const throwingFunction = () => { | |
throw new Error('Ghaaa!'); |
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
/* | |
Implement the array flat function. | |
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat | |
Creates a new array with all sub-array elements concatenated into it recursively up to the specified depth. | |
var arr1 = [1, 2, [3, 4]]; | |
arr1.flat(); // [1, 2, 3, 4] | |
var arr2 = [1, 2, [3, 4, [5, 6]]]; | |
arr2.flat(); // [1, 2, 3, 4, [5, 6]] |
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
export const cancellablePromise = promise => { | |
let isCanceled = false; | |
const wrappedPromise = new Promise((resolve, reject) => { | |
promise.then( | |
value => (isCanceled ? reject({ isCanceled, value }) : resolve(value)), | |
error => reject({ isCanceled, error }), | |
); | |
}); |
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 React, { PropTypes } from 'react'; | |
const Repeater = function(props, context) { | |
const count = props.count || 1; | |
const temp = []; | |
for (let i = 0; i < count; i++) { | |
temp.push(props.children); | |
} | |
console.log(temp); |
NewerOlder