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 a function that takes two arrays as input, each array contains a list of A-Z; | |
// Your program should return True if the 2nd array is a subset of 1st array, or False if not. | |
// For example: | |
// isSubset([A,B,C,D,E], [A,E,D]) = true | |
// isSubset([A,B,C,D,E], [A,D,Z]) = false | |
// isSubset([A,D,E], [A,A,D,E]) = true | |
import { test, expect } from "vitest"; |
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 { test, expect, describe } from "vitest"; | |
function recur(n: number, cur?: number): number { | |
if (!cur) { | |
cur = 0; | |
} | |
if (n < 2) { | |
throw new Error("Invalid input"); | |
} | |
if (n === 2) { |
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
/** | |
Design and implement a data structure for a cache, | |
which has the following functions: | |
- `get(key)` | |
Return the value associated with the specified key | |
if it exists in the cache, else return -1 . | |
- `put(key, value, weight)` | |
Associate with key in the cache, | |
such that might be later retrieved by `get(key)`. |
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 { test, expect } from "vitest"; | |
function isLowercase(char: string): boolean { | |
return char >= "a" && char <= "z"; | |
} | |
function isUppercase(char: string): boolean { | |
return char >= "A" && char <= "Z"; | |
} |
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 PromiseState = "initial" | "pending" | "success" | "error"; | |
export function wrapForSuspense<Task extends (...args: any[]) => Promise<any>>( | |
task: Task | |
) { | |
let status: PromiseState = "initial"; | |
let result: Awaited<ReturnType<Task>>; | |
let suspend: Promise<void>; | |
return (...args: Parameters<Task>) => { |
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
def is_amax(card_number): | |
return re.search(r"(?=\b.{15}\b)^(34|37)", card_number) | |
def is_master_card(card_number): | |
return re.search(r"(?=\b.{16}\b)^5[1..5]", card_number) | |
def is_visa(card_number): | |
return re.search(r"(?=\b.{13,16}\b)^4", card_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
/** | |
* Array | |
* === | |
* Basic array | |
*/ | |
import { pipe } from "fp-ts/lib/function"; | |
import * as Array from "fp-ts/Array"; | |
const foo = [1, 2, 3, 4, 5]; |
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
/** | |
* chain and orElse | |
* === | |
* sequential asynchronous processing can combined with chain and orElse | |
*/ | |
import { pipe } from "fp-ts/lib/function"; | |
import { | |
chain, | |
tryCatch, |
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
/** | |
* Chain with Either | |
* === | |
* chain help solve nested either structure | |
*/ | |
import { flow, pipe } from "fp-ts/lib/function"; | |
import { Password, validate } from "./_prepare"; | |
import { map, Either, chain, right } from "fp-ts/Either"; |
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 { describe } from "../utils"; | |
/** | |
* Task | |
* === | |
* A task is a function that returns a promise which is expected to never be rejected. | |
*/ | |
/** | |
* Why use Task? |
NewerOlder