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 NumberArr = { '0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9 } | |
type Count<A, S extends 0[] = []> = A extends S['length'] ? S : Count<A, [...S, 0]> | |
type Add<A, B> = [...Count<A>, ...Count<B>]['length'] | |
type ParseInt<T extends string> | |
= T extends `${infer N extends number}` ? N : never; | |
type Combine<A extends number, B extends number> = | |
ParseInt<`${A}${B}`> |
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 Count<A, S extends 0[] = []> = A extends S['length'] ? S : Count<A, [...S, 0]> | |
type Add<A, B> = [...Count<A>, ...Count<B>]['length'] | |
type Min<A, B, C extends 0[] = []> = C['length'] extends A | |
? B | |
: C['length'] extends B | |
? A | |
: Min<A, B, [0, ...C]> | |
// ==== |
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 Count<A, S extends 0[] = []> = A extends S['length'] ? S : Count<A, [...S, 0]> | |
type Increment<A> = [...Count<A>, 0]['length'] | |
type Decrement<A> = Count<A> extends [infer A, ...infer Rest] ? Rest['length'] : A | |
type Add<A, B> = [...Count<A>, ...Count<B>]['length'] | |
type Multiply<A, B, S = 0> = B extends 0 ? S : Multiply<A, Decrement<B>, Add<S, A>> | |
type Power<A, B, S = A> = B extends 1 ? S : Power<A, Decrement<B>, Multiply<S, A>> | |
type Square<A> = Power<A, 2> | |
type Cube<A> = Power<A, 3> | |
type Incremented = Increment<10> |
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 CharMap<T extends string = 'aA-bB-cC-dD-eE-fF-gG-hH-iI-jJ-kK-lL-mM-nN-oO-pP-qQ-rR-sS-tT-uU-vV-wW-xX-yY-zZ'> = | |
T extends `${infer Lower}-${infer Upper}` | |
? Lower | CharMap<Upper> | |
: T | |
type CharSplit<T extends string> = T extends `${infer Lower}${infer Upper}` ? [Lower, Upper] : T | |
type CharObj = { [T in CharMap as CharSplit<T>[0]]: CharSplit<T>[1] }; | |
type GetUpperCase<TChar extends keyof CharObj> = CharObj[TChar] | |
type Spongebobify<TPhrase extends string, TResult extends string = '', TFlip = 0> = | |
TPhrase extends `${infer Head}${infer Tail}` | |
? Head extends keyof CharObj |
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 CensorWithChar<TPhrase extends string, TChar extends string, TResult extends string = ''> = | |
TPhrase extends `${infer Head}${infer Tail}` | |
? CensorWithChar<Tail, TChar, `${TResult}${Head extends TChar ? '*' : Head}`> | |
: TResult | |
type CensorWithCharTest = CensorWithChar<'my name is mary celeste', 'm' | 'c'> | |
// type CensorWithCharTest = "*y na*e is *ary *eleste" | |
type Reverse<TPhrase extends string, TResult extends string = ''> = | |
TPhrase extends `${infer Head}${infer Tail}` |
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 React from "react"; | |
import styled, { css } from "styled-components"; | |
const directions = { | |
T: "top", | |
L: "left", | |
R: "right", | |
B: "bottom" | |
}; |