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
function debounce(callback, timer) { | |
let timeoutId; | |
return (...args) => { | |
// save the current context (this) | |
const context = this; | |
// clear the existing timeout | |
clearTimeout(timeoutId); |
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 countries = [ | |
{ value: 'AFG', name: 'Afghanistan' }, | |
{ value: 'ALA', name: 'Aland Island' }, | |
{ value: 'ALB', name: 'Albania' }, | |
{ value: 'DZA', name: 'Algeria' }, | |
{ value: 'ASM', name: 'American Samoa' }, | |
{ value: 'AND', name: 'Andorra' }, | |
{ value: 'AGO', name: 'Angola' }, | |
{ value: 'AIA', name: 'Anguilla' }, | |
{ value: 'ATG', name: 'Antigua and Barbuda' }, |
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
// all credits for this gist goes to Bruno's video | |
// https://www.youtube.com/watch?v=vXh4PFwZFGI | |
type DrawerProps = { fullName: string } & ( | |
| { shape: 'circle'; radius: number } | |
| { shape: 'square'; width: number } | |
| { shape: 'rectangle'; width: number; height: number } | |
); | |
<Drawer fullName="Marek Dano" shape="rectangle" width={5} height={4} /> |
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 factorial = num => (num > 1 ? num * factorial(num - 1) : 1) | |
const memoize = fn => { | |
const cache = {} | |
// with multiple arguments | |
// return (...args) => { | |
// const key = JSON.stringify(args) | |
// return key in cache ? cache[key] : cache[key] = fn.apply(null, args) | |
// } |
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 curry = (fn) => { | |
const curried = (...args) => { | |
if (args.length >= fn.length) { | |
return fn(...args) | |
} else { | |
return (...innerArgs) => curried(...args, ...innerArgs) | |
} | |
} | |
return curried | |
} |
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 multiply = (a, b) => a * b | |
function prefillFunction (fn, prefilledValue) { | |
const inner = liveInput => { | |
const output = fn(liveInput, prefilledValue) | |
return output | |
} | |
return inner | |
} |
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
function fail(arr: never): never { | |
return new Error; | |
} | |
function pluck<T, K extends keyof T>(obj: T, propertyNames: K[]): T[K][] { | |
return propertyNames.map(key => obj[key]) | |
} | |
interface Author { | |
name: string; |
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, { useState, useRef, useEffect } from "react"; | |
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | |
import { faCheck } from "@fortawesome/free-solid-svg-icons"; | |
import { library } from "@fortawesome/fontawesome-svg-core"; | |
import "./styles.css"; | |
library.add(faCheck); | |
/* |
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
// MAP | |
function map(array, callbackFunction) { | |
var newArray = []; | |
for (var i = 0; i < array.length; i++) { | |
newArray[i] = callbackFunction(array[i]); | |
} | |
return newArray; | |
} | |
// Test |
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
// write function for fibonacci numbers where | |
// F[1]=F[2]=1; F[3]=2; F[4]=3; => 1,1,2,3,5,8,... | |
const fibRec = n => { | |
if (n === 1 || n === 2) { | |
return 1 | |
} | |
return fibRec(n-1) + fibRec(n-2) | |
} | |
const fibImp = n => { |
NewerOlder