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
| export default function createSubset(array) { | |
| class Node { | |
| constructor(level, antiparticle = false) { | |
| this.level = level; | |
| this.v = array[level]; | |
| this.l = array[level + 1] && new Node(level + 1); | |
| this.r = array[level + 1] && new Node(level + 1, true); | |
| this.antiparticle = antiparticle; | |
| this.visited = false; | |
| } |
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 createDoublyLinkedList = arr => { | |
| class Node { | |
| constructor(v) { | |
| this.v = v; | |
| this.l = null; | |
| this.r = null; | |
| } | |
| static createNode(v) { | |
| return new Node(v); | |
| } |
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
| class Defer { | |
| constructor() { | |
| this.promise = new Promise((resolve, reject) => | |
| Object.assign(this, {resolve, reject}) | |
| ); | |
| } | |
| } |
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 httpCancellatorForAxios(fn, axiosInstance) { | |
| const configArgIndices = [ | |
| ["request", 0], | |
| ["get", 1], | |
| ["delete", 1], | |
| ["head", 1], | |
| ["options", 1], | |
| ["post", 2], | |
| ["put", 2], | |
| ["patch", 2], |
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
| "use strict"; | |
| /** | |
| * directive @paginate on FIELD_DEFINITION | |
| * """ | |
| * abstract type Page { | |
| * totalCount: Int! | |
| * edges: [Edge!]! | |
| * pageInfo: PageInfo! | |
| * } |
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 fisherYatesShuffle(array) { | |
| const {length} = array; | |
| array.forEach((value, index) => { | |
| const rand = (index + Math.random() * (length - index)) | 0; | |
| rand !== index && ([array[index], array[rand]] = [array[rand], value]); | |
| }); | |
| return array; | |
| } |
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 throttle(fn, wait) { | |
| let timestamp = -wait || 0; | |
| return function throttled(...args) { | |
| const now = performance.now(); | |
| now - timestamp > wait && (timestamp = now) && fn.apply(this, args); | |
| }; | |
| } |
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 debounce(fn, wait) { | |
| let cancelId = null | |
| const hasWait = Number.isSafeInteger(wait) | |
| const [timer, cancel] = | |
| hasWait | |
| ? [setTimeout, clearTimeout] | |
| : [requestAnimationFrame, cancelAnimationFrame] | |
| return function debounced(...args) { | |
| cancel(cancelId) | |
| cancelId = timer(fn.bind(this, ...args), wait) |
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 computeAverageRandomSort(length = 16, iteration = 1024) { | |
| function generateRandomArray() { | |
| return Array.from({length}) | |
| .map((_, i) => i) | |
| .sort(() => Math.random() - .5); | |
| } | |
| const arrays = Array.from({length: iteration}).map(generateRandomArray); | |
| return Array.from({length}).map( | |
| (_, i) => | |
| arrays.map(array => array[i]).reduce((sum, value) => sum + value) / iteration |
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 getSamples(length) { | |
| const array = Array.from(this || []); | |
| const sampleLength = Math.min(length, array.length); | |
| const result = []; | |
| while (result.length < sampleLength) { | |
| const draw = Math.random() * array.length; | |
| const sample = array.splice(draw, 1).shift(); | |
| result.push(sample); | |
| } | |
| return result; |
NewerOlder