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 HashTable { | |
constructor(bucketSize = 1024) { | |
this._bucketSize = bucketSize; | |
this._data = new Array(bucketSize); | |
} | |
hashKey(key) { | |
const h = JSON.stringify(key, Object.keys(key).sort()) | |
.split('') | |
.reduce((acc, cur, i) => acc + cur.charCodeAt(0) * (i+1), 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
const promiseCache = (promFn) => { | |
let cachedPromise = promFn(); | |
return (refreshCache = false) => { | |
if (refreshCache) cachedPromise = promFn(); | |
return cachedPromise; | |
} | |
} | |
// Pass a function that generates a promise instead of the promise, so it can be refreshed | |
const cachedPromise = promiseCache(() => Promise.resolve(Math.random())); |
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 validUnits = ['km', 'm', 'cm', 'mm', 'in', 'ft', 'mile']; | |
const isLengthObj = (lo) => | |
'_val' in lo && | |
'_unit' in lo && | |
typeof lo._val === 'number' && | |
typeof lo._unit === 'string' && | |
validUnits.includes(lo._unit); | |
const formatUnit = (unit, val) => { |
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 daggy = require('daggy'); | |
const {identity} = require('ramda'); | |
const Either = daggy.taggedSum('Either', { | |
Left: ['__value'], | |
Right: ['__value'], | |
}); | |
Either.of = Either.Right; |
NewerOlder