StartsWith
提出詳細
type Reverse<S extends string> = S extends `${infer S1}${infer S2}` ? `${Reverse<S2>}${S1}` : "" type StartsWith<T extends string, U extends string> = U extends `${infer U1}${infer U2}` ? T extends `${U1}${infer T2}` ? StartsWith<T2,U2> : false : true type EndsWith<T extends string, U extends string> = StartsWith<Reverse<T>,Reverse<U>>
提出日時 | 2023-09-15 13:17:43 |
---|---|
問題 | StartsWith |
ユーザー | sankantsu |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<StartsWith<'abc', 'ac'>, false>>, Expect<Equal<StartsWith<'abc', 'ab'>, true>>, Expect<Equal<StartsWith<'abc', 'abcd'>, false>>, Expect<Equal<StartsWith<'abc', ''>, true>>, Expect<Equal<StartsWith<'abc', ' '>, false>>, ]