FunctionRacerProblemsRace

Reformat Phone Number

EasyStringsPython, JavaScript, TypeScript, Java, C++

number has digits, spaces and dashes. Remove the spaces and dashes, then group the digits from left to right into blocks of 3 separated by -, with this rule for the end:

Return the formatted string.

Example 1

number "1-23-45 6"
returns "123-456"

Digits 123456 give 123-456.

Example 2

number "123 4-567"
returns "123-45-67"

Digits 1234567 give 123-45-67.

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