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 { createQueue } from './queueu'; | |
function createPriorityQueue() { | |
const lowPriorityQueue = createQueue(); | |
const highPriorityQueue = createQueue(); | |
return { | |
enqueue(item, isHighPriority = false) { | |
isHighPriority | |
? highPriorityQueue.enqueue(item) |
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 createStack() { | |
const array = []; | |
return { | |
push(item) { | |
array.push(item); | |
}, | |
pop() { | |
return array.pop(); | |
}, | |
get length() { |
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 createNode(value) { | |
return { | |
value: value, | |
next: null | |
} | |
}; | |
function createLinkedList() { | |
return { | |
head: null, |
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
/* | |
Questions: | |
* What do you think PFC.props is doing? | |
- Creating a Object with reference parameters, map your keys; | |
* What is the concurrency variable good for? | |
- Its as especifique option where limits the number of Promise created. | |
* sendOutStatusEmails ignores errors (except for logging them). | |
Let's say your task was to make sure the whole function fails as soon sending out any | |
email failed. How would you adjust the code? | |
- follows the code: |
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) |
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 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 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 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
// 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; |