FunctionRacerProblemsRace

Reverse Prefix of Word

BeginnerStringsPython, JavaScript, TypeScript, Java, C++

Find the first place the single character ch appears in word. Return word with the part from the start up to and including that character reversed.

If ch does not appear in word, return word unchanged.

Example 1

word "abcdefd"
ch "d"
returns "dcbaefd"

The first d is at index 3, so abcd becomes dcba: dcbaefd.

Example 2

word "xyz"
ch "a"
returns "xyz"

a is missing, so nothing changes.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Strings problems