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 BST = { | |
key: number; | |
value: string; | |
left: BST | false; | |
right: BST | false; | |
} | false; | |
const BST0: BST = false; | |
const BST1: BST = { | |
key: 1, |
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 { getProviderStatusAsync, LocationProviderStatus } from 'expo-location'; | |
import { useState } from 'react'; | |
import { Platform } from 'react-native'; | |
import useInterval from 'use-interval'; | |
const useLocationProviderStatus = (delay: number = 2000) => { | |
const [locationProviderAvailable, setLocationProviderAvailable] = useState<boolean | undefined>(undefined); | |
const getLocationProviderStatus = ({ | |
gpsAvailable, |
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 doubleList(listOfNumbers: number[]): number[] { | |
if(!listOfNumbers.length) return []; | |
return [ | |
double(listOfNumbers[0]), | |
...doubleList(listOfNumbers.slice(1, listOfNumbers.length)) | |
]; | |
} | |
function double(n: 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
(check-expect (fact 0) 1) | |
(check-expect (fact 3) 6) | |
(define (fact n) | |
(cond [(zero? n) 1] | |
[else | |
(* n | |
(fact (sub1 n)))])) |
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 asEnumeration = dictionary => Object.freeze({ | |
from(value) { | |
if (dictionary[value]) { | |
return dictionary[value]; | |
} | |
throw Error(`Invalid enumeration value ${value}`); | |
} | |
}); | |
const getEvenNumbers = limit => includeIfConditionIsMet(limit, number => number % 2 === 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
const generateIncrementedNumbersList = (min, max, increment, includeMin) => { | |
const items = []; | |
let incrementor = Math.max(min, increment); | |
if (includeMin) { | |
items.push(min); | |
} | |
while (incrementor <= max) { | |
items.push(incrementor); |
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 add = (a, b) => a + b; | |
const add10 = num => add(num, 10); | |
const add200 = num => add(num, 200); | |
const addNew = a => b => a + b; | |
console.log(add(10, 20)) // 30 | |
console.log(add10(10)) // 20 | |
console.log(addNew(10)(20)) // 30 | |
console.log(add200(10)) // 210 |
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 rxRangeSlider = ({ rangeNode, handlesContainerNode, handleStartNode, handleEndNode, start: [stepStart, stepEnd], stepSize, bounds: [rangeStart, rangeEnd] }) => { | |
const KEY_LEFT = 37; | |
const KEY_RIGHT = 39; | |
const VALID_KEYS = [KEY_LEFT, KEY_RIGHT]; | |
const INCREMENT_LOWER = 'INCREMENT_LOWER'; | |
const DECREMENT_LOWER = 'DECREMENT_LOWER'; | |
const INCREMENT_UPPER = 'INCREMENT_UPPER'; | |
const DECREMENT_UPPER = 'DECREMENT_UPPER'; | |
const restrictToRange = (min, max, num) => Math.min(Math.max(min, num), max); |
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 omit = (object, key) => { | |
const objectCopy = Object.assign({}, object); | |
Object.keys(objectCopy).forEach(itemKey => { | |
if(key === itemKey) { | |
delete objectCopy[itemKey]; | |
} | |
}) | |
return objectCopy; | |
}; |
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
Rx.Observable.range(1, 10) | |
.toArray() | |
.mergeMap(items => Rx.Observable.from(items)) | |
.map(a => a + a) | |
.subscribe({ | |
next(items) { | |
console.log(items); | |
} |