Type Challenges Judge

String Join

提出詳細

type Join<In extends string[], Sep extends string = ""> = In extends [infer L extends string, infer R extends string, ...infer Rest extends string[]] ? Join<[`${L}${Sep}${R}`, ...Rest], Sep> : In[0] extends string ? In[0] : "" declare function join<Sep extends string>(delimiter: Sep): <T extends string[], S extends string = Sep>(...parts: T) => Join<T, S>
提出日時2024-09-12 08:03:23
問題String Join
ユーザーookkoouu
ステータスAccepted
テストケース
import type { Equal, Expect } from '@type-challenges/utils' // Edge cases const noCharsOutput = join('-')() const oneCharOutput = join('-')('a') const noDelimiterOutput = join('')('a', 'b', 'c') // Regular cases const hyphenOutput = join('-')('a', 'b', 'c') const hashOutput = join('#')('a', 'b', 'c') const twoCharOutput = join('-')('a', 'b') const longOutput = join('-')('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h') type cases = [ Expect<Equal<typeof noCharsOutput, ''>>, Expect<Equal<typeof oneCharOutput, 'a'>>, Expect<Equal<typeof noDelimiterOutput, 'abc'>>, Expect<Equal<typeof twoCharOutput, 'a-b'>>, Expect<Equal<typeof hyphenOutput, 'a-b-c'>>, Expect<Equal<typeof hashOutput, 'a#b#c'>>, Expect<Equal<typeof longOutput, 'a-b-c-d-e-f-g-h'>>, ]