View function-pipe.js
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 pipe = (...functions) => args => functions.reduce((arg, fn) => fn(arg), args); | |
// const league = [ | |
// { heroe: "superman", power: 'fly' }, | |
// { heroe: "batman", power: 'millionare'}, | |
// { heroe: "flash", power: 'speed' }, | |
// ] | |
// const filter = f => arr => arr.filter(f); | |
// const map = m => arr => arr.map(m); |
View function-compose.js
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 compose = (...functions) => args => functions.reduceRight((arg, fn) => fn(arg), args); | |
// Example: | |
// const league = [ | |
// { heroe: "superman", power: 'fly' }, | |
// { heroe: "batman", power: 'millionare'}, | |
// { heroe: "flash", power: 'speed' }, | |
//] | |
//const filter = f => arr => arr.filter(f); | |
//const map = m => arr => arr.map(m); |
View Debounce_decorator.js
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
/** | |
* Debounce a method | |
*/ | |
function debounce(ms) { | |
return function(target: any, key: any, descriptor: any) { | |
const oldFunc = descriptor.value | |
const newFunc = _debounce(oldFunc,ms) | |
descriptor.value = function() { | |
return newFunc.apply(this,arguments) |
View fetch-typeScript-async-await.ts
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
// declaring fetch + async-await + TypeScript | |
export async function get<T>( | |
path: string, | |
args: RequestInit = { method: "get" } | |
): Promise<HttpResponse<T>> { | |
return await http<T>(new Request(path, args)); | |
}; | |
export async function post<T>( | |
path: string, |
View debounce.js
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 debounce = (fn, time) => { | |
let timerId; | |
return function(...args) { | |
const functionCall = () => fn.apply(this, args); | |
clearTimeout(timerId); | |
timerId = setTimeout(functionCall, time); | |
}; | |
}; |
View gist:7eeb38b700059630ccf71c60d6f071af
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 startCountingForHideAndSeek() { | |
// State for managing cleanup and cancelling | |
let finished = false; | |
let cancel = () => finished = true; | |
const promise = new Promise((resolve, reject) => { | |
// | |
// Custom Promise Logic | |
// | |
// NOTE: This countdown not finish in exactly 10 seconds, don't build timers this way! |
View quick_sort.js
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
'use strict'; | |
function swap(arr, ind1, ind2) { | |
let temp = arr[ind1]; | |
arr[ind1] = arr[ind2]; | |
arr[ind2] = temp; | |
} | |
function quickSortInPlace(arr, left, right) { | |
left = left || 0; |
View gist:dd5a196c183d9fb21942ae4f39a0911c
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
## DFS & BFS: | |
DFS = storing the vertices "stacks", stacks are LIFO (push, pop). | |
BFS = storing the vertices "queue", queues are FIFO (shift, unshift or enqueue and dequeue). | |
## Why to use BFS and DFS? | |
#### DFS = memory requirements than BFS. It will take a lot of memory to traverse deeper trees while it works well with wider trees. | |
commonly used when you need to search the entire tree. | |
#### BFS = is better for deeper trees since it will take a lot more memory to operate on wider trees. | |
## When to use BFS and DFS? |
View create-react-app-scss
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
npx create-react-app my-app | |
cd my-app | |
yarn add node-sass -S | |
// Change .css files to .scss | |
// Change any imports to use .scss | |
yarn start |
View delayPromise,js
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 delayPromise(delay, value) { | |
console.time(); | |
// using built-in Promise constructor-function/class. | |
return new Promise(function(resolve) { | |
setTimeout(function() { | |
console.timeEnd(); | |
resolve(value); | |
}, delay); | |
}); | |
} |
NewerOlder