View expand.ts
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 LeftRight = 'left' | 'right'; | |
type LeftRightNet = 'left' | 'right' | 'net'; | |
type ExpandNumericFields<Str> = Str extends `${infer Prefix}_contribution` ? `${Prefix}_contribution_${LeftRightNet}` : Str extends 'weight' ? `weight_${LeftRightNet}` : Str extends string ? `${Str}_${LeftRight}` : never; | |
type T1 = ExpandNumericFields<'base_contribution'> | |
type T2 = ExpandNumericFields<'weight'> | |
type T3 = ExpandNumericFields<'currency_exposure'> |
View safe.js
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 ordinal(number) { | |
const englishOrdinalRules = new Intl.PluralRules("en", { type: "ordinal" }); | |
const suffixes = { | |
one: "st", | |
two: "nd", | |
few: "rd", | |
other: "th" | |
}; | |
const suffix = suffixes[englishOrdinalRules.select(number)]; |
View testUtils.ts
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, selectors } from '@playwright/test'; | |
import { readFile } from 'fs-extra'; | |
import type * as TestingLibraryDom from '@testing-library/dom'; | |
// This type was copied across from Playwright's repo. | |
// See: https://github.com/microsoft/playwright/blob/82ff85b106e31ffd7b3702aef260c9c460cfb10c/packages/playwright-core/src/client/types.ts#L108-L117 | |
type SelectorEngine = { | |
/** | |
* Returns the first element matching given selector in the root's subtree. |
View at.js
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 AtRange = number | [number, number]; | |
const at = <T>(arr: T[], ...ranges: AtRange[]): (T | undefined)[] => | |
ranges.flatMap((range) => { | |
if (typeof range === "number") { | |
return range >= 0 ? arr[range] : arr[arr.length + range - 1]; | |
} | |
return range[0] >= 0 | |
? arr.slice(range[0], range[1] + 1) |
View insertInterval.js
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 insertValue(array, index, value) { | |
const newArray = [...array]; | |
newArray.splice(index, 0, value); | |
return newArray; | |
} | |
function replaceValue(array, start, end, value) { | |
const newArray = [...array]; | |
newArray.splice(start, 1 + (end - start), value); | |
return newArray; |
View bst.js
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
class Node { | |
constructor(value, left = null, right = null) { | |
this.value = value; | |
this.left = left; | |
this.right = right; | |
} | |
find(value) { | |
let current = this; |
View JsonViewer.js
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 { useCallback, useState } from "react"; | |
const MAXIMUM_DEPTH = 1; | |
function Node({ | |
value, | |
depth = 1, | |
isExpandedDefault = depth <= MAXIMUM_DEPTH | |
}) { | |
const [isExpanded, setIsExpanded] = useState(isExpandedDefault); |
View valueEquality.ts
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 stringify from "fast-json-stable-stringify"; | |
type ImmutablePrimitive = | |
| undefined | |
| null | |
| boolean | |
| string | |
| number | |
| Function; |
View threeSum.js
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 defaultKey = (arr) => arr.join(""); | |
function createPermute(toKey = defaultKey) { | |
return function* permute(arr, length = arr.length) { | |
if (length > arr.length) { | |
throw new Error( | |
`The permutation size required (${length}) is greater than the size of the array supplied (${arr.length}).` | |
); | |
} |
View findIndexOfMatchingParantheses.js
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 isOpeningParantheses(char) { | |
return char === "(" || char === "[" || char === "{" || char === "<"; | |
} | |
function isClosingParantheses(char) { | |
return char === ")" || char === "]" || char === "}" || char === ">"; | |
} | |
function isParantheses(char) { | |
return isOpeningParantheses(char) || isClosingParantheses(char); |
NewerOlder