Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2822 - Split #3066

Open
akcyp opened this issue Sep 3, 2021 · 2 comments
Open

2822 - Split #3066

akcyp opened this issue Sep 3, 2021 · 2 comments
Labels
2822 answer Share answers/solutions to a question en in English

Comments

@akcyp
Copy link

akcyp commented Sep 3, 2021

https://tsplay.dev/mLlrvm

type Split<T extends string, S extends string> =
  string extends T
    ? string[]
    : T extends `${infer X}${S}${infer Y}`
      ? [X, ...Split<Y, S>]
      : T extends ''
        ? S extends '' ? [] : ['']
        : [T];

/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'
import { ExpectFalse, NotEqual } from '@type-challenges/utils'

type cases = [
  Expect<Equal<Split<'Hi! How are you?', 'z'>, ['Hi! How are you?']>>,
  Expect<Equal<Split<'Hi! How are you?', ' '>, ['Hi!', 'How', 'are', 'you?']>>,
  Expect<Equal<Split<'Hi! How are you?', ''>, ['H', 'i', '!', ' ', 'H', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u', '?']>>,
  Expect<Equal<Split<'', ''>, []>>,
  Expect<Equal<Split<'', 'z'>, ['']>>,
  Expect<Equal<Split<string, 'whatever'>, string[]>>,
]
@akcyp akcyp added answer Share answers/solutions to a question en in English labels Sep 3, 2021
@github-actions github-actions bot added the 2822 label Sep 3, 2021
@Lionad-Morotar
Copy link
Contributor

Your code cant pass all test cases bro

@akcyp
Copy link
Author

akcyp commented Apr 22, 2022

@Lionad-Morotar Fixed, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2822 answer Share answers/solutions to a question en in English
Projects
None yet
Development

No branches or pull requests

2 participants