Loading...
00274
integers-comparator
enum Comparison { Greater, Equal, Lower, } type LengthOfString<S extends Readonly<string>, L extends string[] = []> = S extends '' ? L['length'] : S extends `${infer First}${infer Last}` ? LengthOfString<Last, [First,...L]> : never; type NotEqualSignCompare<A extends number, B extends number> = IsNegative<NumberToString<A>> extends true ? Comparison.Lower : Comparison.Greater type NumberToString<T extends number> = `${T}`; type IsNegative<A extends string> = A extends `-${infer N}` ? true : false; type EqualSign<A extends number, B extends number> = IsNegative<NumberToString<A>> extends IsNegative<NumberToString<B>> ? true : false; type EqualDigit<A extends number, B extends number> = EqualSign<A,B> extends true ? LengthOfString<NumberToString<A>> extends LengthOfString<NumberToString<B>> ? true : false : false; type GetCompareNums<A extends string, B extends string> = A extends `${infer AFirst}${infer ARest}` ? B extends `${infer BFirst}${infer BRest}` ? AFirst extends BFirst ? GetCompareNums<ARest, BRest> : [AFirst, BFirst] : never : never type ALowerThenB<T extends string[]>= T extends [infer F extends string, infer L extends string] ? `${F}${L}` extends LowerCompare ? true : false : never; type LowerCompare = `0${'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'}` | `1${'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'}` | `2${|'3'|'4'|'5'|'6'|'7'|'8'|'9'}` | `3${'4'|'5'|'6'|'7'|'8'|'9'}` | `4${'5'|'6'|'7'|'8'|'9'}` | `5${'6'|'7'|'8'|'9'}` | `6${'7'|'8'|'9'}` | `7${'8'|'9'}` | `8${'9'}`; type Comparator<A extends number, B extends number> = A extends B ? Comparison.Equal : EqualSign<A,B> extends true ? EqualDigit<A,B> extends true ? GetCompareNums<`${A}`,`${B}`> extends [infer F extends string, infer L extends string] ? ALowerThenB<[F,L]> extends true ? IsNegative<`${A}`> extends true ? Comparison.Greater : Comparison.Lower : IsNegative<`${A}`> extends true ? Comparison.Lower : Comparison.Greater : never : ALowerThenB< IsNegative<`${A}`> extends true ? [`${LengthOfString<`${B}`>}`,`${LengthOfString<`${A}`>}`] : [`${LengthOfString<`${A}`>}`,`${LengthOfString<`${B}`>}`] > extends true ? Comparison.Lower:Comparison.Greater : NotEqualSignCompare<A,B>
Link

본 페이지는 상업적 목적이 아닌

개인 포트폴리오 공개용이며

코드는 깃허브에 모두 공개되어 있습니다.

NextJS Typescript react-query @chakra-ui 로 제작되었습니다.