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 FACTS = [ | |
'm = 3.28 ft', | |
'ft = 12 in', | |
'hr = 60 min', | |
'min = 60 sec', | |
] | |
const QUERY = '2 m = ? in' | |
const CORRECT_ANSWER = 78.72 |
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
// write async generator to return N random strings per call | |
// add parameter to limit total amount of strings returned by generator | |
// write async mapper that accepts async generator as argument and | |
// a callback that is applied for every generator result | |
// mapper should return all generator results as array | |
async function getLinesTotal() { | |
return 8 |
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 grid = [ | |
[3, 1, 1, 1], | |
[2, 1, 0, 1], | |
[1, 1, 0, 2], | |
[2, 0, 1, 0], | |
] | |
interface Area { | |
value: number | |
points: Set<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
#include <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
typedef struct graph_node { | |
char *name; | |
struct graph_node *parent; | |
struct graph_node **children; | |
size_t children_size; | |
size_t children_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
function floodFill( | |
image: number[][], | |
x: number, | |
y: number, | |
newColor: number, | |
): void { | |
const minY = 0 | |
const maxY = image.length - 1 | |
if (maxY < 0) { return } |
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
async function promiseAll<T = unknown>(promises: Promise<T>[]): Promise<T[]> { | |
const results: T[] = [] | |
for (let i = 0; i < promises.length; ++i) { | |
results.push(await promises[i]) | |
} | |
return results | |
} |
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 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 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 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 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) { |
NewerOlder