Skip to content

Commit

Permalink
feat: medium-join
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouzhenpan committed Jul 25, 2024
1 parent 3aa8158 commit 550a218
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/05310-medium-join.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// ============= Test Cases =============
import type { Equal, Expect } from './test-utils'

type cases = [
Expect<Equal<Join<['a', 'p', 'p', 'l', 'e'], '-'>, 'a-p-p-l-e'>>,
Expect<Equal<Join<['Hello', 'World'], ' '>, 'Hello World'>>,
Expect<Equal<Join<['2', '2', '2'], 1>, '21212'>>,
Expect<Equal<Join<['o'], 'u'>, 'o'>>,
Expect<Equal<Join<[], 'u'>, ''>>
]

// ============= Your Code Here =============
type Join<
T extends any[],
U extends string | number,
Result extends string = ''
> = T extends [infer A, ...infer B]
? Join<
B,
U,
Result extends '' ? `${A & string}` : `${Result}${U}${A & string}`
>
: Result

0 comments on commit 550a218

Please sign in to comment.