progress bar exemples study https://jsbin.com/tufuyifazo/edit?html,console,output
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
type EventTarget<T> = EventTarget & T; | |
interface FormEvent<T> extends Event { | |
target: EventTarget<T>; | |
} | |
function handleSubmit(event: FormEvent<{price: number}>) { | |
event.target.price; | |
} |
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 button = document.querySelector('button'); | |
button.addEventListener("click", () => resizeWithTroattle(10)); | |
const resizeWithTroattle = throttle(executeResize, 3000); | |
window.addEventListener("resize", () => resizeWithTroattle('test')); | |
function executeResize(number) { | |
console.log("resize: " + number); | |
} | |
function throttle(fn, time) { |
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 makeInterable = (array) => { | |
let nextIndex = 0; | |
return { | |
next: () => { | |
if (nextIndex < array.length) { | |
return {value: array[nextIndex ++], done: false} | |
} else { | |
return {done: true}; | |
} |
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 deepClone = obj => { | |
const clone = {} | |
for (let i in obj) { | |
if (obj[i] != null && typeof obj[i] === 'object') { | |
clone[i] = deepClone(obj[i]) | |
} else { | |
clone[i] = obj[i] | |
} | |
} | |
return clone |
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, wait, immediate) => { | |
let timeout; | |
return () => { | |
const later = () => { | |
timeout = null; | |
if (!immediate) fn.apply(this) | |
} | |
const callNow = immediate && !timeout; | |
clearTimeout(timeout) | |
timeout = setTimeout(later, wait) |
boucing loading animation https://jsbin.com/xevusopuza/edit?html,css,output
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
// Return the total number of matching pairs of socks that John can sell. | |
// 9 | |
// 10 20 20 10 10 30 50 10 20 | |
// output | |
// 3 | |
function sockMerchant(n, ar) { | |
let totalPair=0; |
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
declare var __DEV__: boolean; | |
declare module 'react-native' { | |
declare type Color = string | number; | |
declare type Transform = | |
{ perspective: number } | | |
{ scale: number } | | |
{ scaleX: number } | |
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
// chunk | |
// Creates an array of elements split into groups the length of size. | |
const chunk = (input, size) => { | |
return input.reduce((arr, item, idx) => { | |
if (idx % size === 0) { | |
return [...arr, [item]]; | |
} else { | |
return [...arr.slice(0, -1), [...arr.slice(-1)[0], item]]; | |
} |
NewerOlder