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
import React from "react"; | |
import { useState, useEffect } from "react"; | |
const render = data => match => | |
data.pending ? match.pending() | |
: data.error ? match.error(data.error) | |
: data.data ? match.data(data.data) | |
: null // prettier-ignore | |
export const useMatchFetch = url => { |
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
// referency https://www.interviewcake.com/concept/javascript/memoization | |
class Fibber { | |
constructor() { | |
this.memo = {}; | |
} | |
fib(n) { | |
if (n < 0) { | |
throw new Error('Index was negative. No such thing as a negative index in a series.'); |
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
// Run asynchronous functions in sequence | |
const peopleArr = [ | |
{ | |
username: 'glestrade', | |
displayname: 'Inspector Lestrade', | |
email: '[email protected]', | |
authHash: 'bdbf9920f42242defd9a7f76451f4f1d', | |
lastSeen: '2019-05-13T11:07:22+00:00', | |
}, |
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 Logger = require('./logger'); | |
const logger = new Logger(); | |
logger.on('message', data => console.log('Called Listener', data)); | |
logger.log('Hello World'); | |
logger.log('Hi'); | |
logger.log('Hello'); |
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
<!-- The issue: alert displays 'undefined' instead of an item from prizes --> | |
<button id="btn-0">Button 1</button> | |
<button id="btn-1">Button 2</button> | |
<button id="btn-2">Button 3</button> | |
<script type="text/javascript"> | |
const prizes = ['A Unicorn!', 'A Hug!', 'Fresh Laundry!']; | |
for (var btnNum = 0; btnNum < prizes.length; btnNum++) { | |
// For each of our buttons, when the user clicks it... |
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 deepClone(obj) { | |
var copy; | |
// Handle the 3 simple types, and null or undefined | |
if (null == obj || "object" != typeof obj) return obj; | |
// Handle Date | |
if (obj instanceof Date) { | |
copy = new Date(); | |
copy.setTime(obj.getTime()); |
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 finds the node you are searching for and expand it and its parent. | |
* | |
* @param {TreeNode} node primeng tree node data | |
* @param {string} propField name of the property you are searching for ex: label | |
* @param {any} searchValue value you are searching for | |
*/ | |
filterExpandRecursive( | |
node: TreeNode, | |
propField: string, |
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 flatten = filter => { | |
const filters = filter.filters; | |
if (filters) { | |
return filters.reduce((acc, curr) => acc.concat(curr.filters ? flatten(curr) : [curr]), []); | |
} | |
return []; | |
}; | |
const rootFilters = { | |
filters: [ |
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
// reference https://medium.com/javascript-scene/master-the-javascript-interview-what-is-function-composition-20dfb109a1a0 | |
const pipe = (...fns) => x => fns.reduce((v, f) => f(v), x); | |
const fn1 = s => s.toLowerCase(); | |
const fn2 = s => s.split('').reverse().join(''); | |
const fn3 = s => s + '!' | |
const newFunc = pipe(fn1, fn2, fn3); | |
const result = newFunc('Time'); // emit! |
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
var vendingMachine = require('./vendingMachine'); | |
vendingMachine.insertCoin('q'); | |
vendingMachine.insertCoin('q'); | |
vendingMachine.insertCoin('q'); | |
vendingMachine.insertCoin('q'); | |
console.log("Insert 100"); | |
console.log("Get product: ", vendingMachine.vendProduct('A1')); | |
console.log("Release: ", vendingMachine.releaseChange()); |