progress bar exemples study https://jsbin.com/tufuyifazo/edit?html,console,output
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
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 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 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 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 makeInterable = (array) => { | |
let nextIndex = 0; | |
return { | |
next: () => { | |
if (nextIndex < array.length) { | |
return {value: array[nextIndex ++], done: false} | |
} else { | |
return {done: true}; | |
} |
boucing loading animation https://jsbin.com/xevusopuza/edit?html,css,output
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
// 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 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
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 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
// 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]]; | |
} |
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 bublesort(arr1) { | |
const arr = [...arr1]; | |
let swap | |
do { | |
swap = false; | |
for (i=0; i < arr.length-1; i++) { | |
if (arr[i] > arr[i+1]) { | |
let tmp = arr[i]; | |
arr[i] = arr[i+1]; | |
arr[i+1] = tmp; |
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 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) |
NewerOlder