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 deepEquals(v1: unknown, v2: unknown): boolean { | |
if (v1 === v2) { return true } // equals | |
const t1 = typeof v1 | |
const t2 = typeof v2 | |
if (t1 !== t2) { return false } // diff types | |
if (t1 !== 'object') { return false } | |
// objects or arrays |
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 S = "sustainable"; | |
const K = "disabling"; | |
interface Tree { | |
[char: string]: Tree; | |
} | |
function buildTree(str: string): Tree { | |
const tree: Tree = {}; | |
const prevs = [tree]; |
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
<root> | |
root | |
<a> | |
a | |
<aa>aa</aa> | |
<bb>bb</bb> | |
</a> | |
<b>b | |
<ba>ba</ba> | |
<bb>bb</bb> |
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
interface PromiseAllContext<T> { | |
results: T[] | |
jobs: (() => Promise<T>)[] | |
launched: number | |
} | |
async function worker<T>(context: PromiseAllContext<T>) { | |
const { jobs, results } = context | |
while (context.launched < jobs.length) { |
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
import 'package:url_launcher/url_launcher.dart'; | |
Future<bool> openUrl(String url) async { | |
if (url == null || url.trim().length == 0) { | |
return false; | |
} | |
url = Uri.encodeFull(url.trim()); | |
if (!url.contains('://')) { |
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 fetch = require("node-fetch") | |
const fetchAll = async function(urls, max=3) { | |
const results = Array(urls.length) | |
const workers = Array(max) | |
const index = {value:0} | |
for (let i=0; i<max; ++i) { | |
workers.push(fetchAll.worker(urls, results, index)) | |
} |
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 rotateWords = function(arr) { | |
rotateWords.reverse(arr, 0, arr.length-1) | |
let firstSpaceIndex = arr.indexOf(" ") | |
let secondSpaceIndex = arr.indexOf(" ", firstSpaceIndex + 1) | |
rotateWords.reverse(arr, 0, firstSpaceIndex - 1) | |
rotateWords.reverse(arr, firstSpaceIndex + 1, secondSpaceIndex - 1) | |
rotateWords.reverse(arr, secondSpaceIndex + 1, arr.length - 1) |
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
// ABAZDC, BACBAD => ABAD | |
// AGGTAB, GXTXAYB => GTAB | |
// aaaa, aa => aa | |
const getLongestSubseq = function(s1, s2) { | |
let longest = null | |
for ( let s1from=0; s1from<s1.length; ++s1from ) { | |
let current = [] | |
let s1i = s1from, s2i = 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 genBrackets = function(n) { | |
const result = [] | |
if ( n > 0 ) { | |
genBrackets.add(n, 0, "", result) | |
} | |
return result.join(" ") | |
} |
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
var moneyTypes = [5000, 1000, 500, 100, 50, 30] | |
var lims = { | |
5000: 4, | |
1000: 5, | |
500: 2, | |
100: 5, | |
50: 100, | |
30: 23 | |
} |