You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We've already done a similar challenge, DropChar which will drop a specific sequence of characters. This one is a bit more complex because it will drop any individual character in the provided pattern. Loops within loops. Turtles all the way down.
🎥 Video Explanation
🔢 Code
// ============= Test Cases =============importtype{Equal,Expect}from'./test-utils'typeA1=DropString<'butter fly!',''>;typeB1='butter fly!';typeC1=Expect<Equal<A1,B1>>;typeA2=DropString<'butter fly!',' '>;typeB2='butterfly!';typeC2=Expect<Equal<A2,B2>>;typeA3=DropString<'butter fly!','but'>;typeB3='er fly!';typeC3=Expect<Equal<A3,B3>>;typeA4=DropString<' b u t t e r f l y ! ','but'>;typeB4=' e r f l y ! ';typeC4=Expect<Equal<A4,B4>>;typeA5=DropString<' butter fly! ',' '>;typeB5='butterfly!';typeC5=Expect<Equal<A5,B5>>;typeA6=DropString<' b u t t e r f l y ! ',' '>;typeB6='butterfly!';typeC6=Expect<Equal<A6,B6>>;typeA7=DropString<' b u t t e r f l y ! ','but'>;typeB7=' e r f l y ! ';typeC7=Expect<Equal<A7,B7>>;typeA8=DropString<' b u t t e r f l y ! ','tub'>;typeB8=' e r f l y ! ';typeC8=Expect<Equal<A8,B8>>;typeA9=DropString<' b u t t e r f l y ! ','b'>;typeB9=' u t t e r f l y ! ';typeC9=Expect<Equal<A9,B9>>;typeA10=DropString<' b u t t e r f l y ! ','t'>;typeB10=' b u e r f l y ! ';typeC10=Expect<Equal<A10,B10>>;// ============= Your Code Here =============typeDropString<T,U>=Textends `${infer Head}${infer Tail}`
? Uextends `${string}${Head}${string}`
? DropString<Tail,U>
: `${Head}${DropString<Tail,U>}`
: '';// ============== Alternatives ==============typeDropChar<T,Uextendsstring>=Textends `${infer Left}${U}${infer Right}`
? DropChar<`${Left}${Right}`,U>
: T;typeDropString<T,U>=Uextends `${infer Head}${infer Tail}`
? DropString<DropChar<T,Head>,Tail>
: T;
➕ More Solutions
For more video solutions to other challenges: see the umbrella list! #21338
The text was updated successfully, but these errors were encountered:
2059 - Drop String
We've already done a similar challenge, DropChar which will drop a specific sequence of characters. This one is a bit more complex because it will drop any individual character in the provided pattern. Loops within loops. Turtles all the way down.
🎥 Video Explanation
🔢 Code
➕ More Solutions
For more video solutions to other challenges: see the umbrella list! #21338
The text was updated successfully, but these errors were encountered: