FunctionRacerProblemsRace

Join the Non-Empty Parts

BeginnerStringsPython, JavaScript, TypeScript, Java, C++

parts is a list of strings and sep is a separator string. Return the single string made by writing the non-empty entries of parts in their original order with sep between neighbouring entries.

Entries equal to the empty string "" are skipped entirely, so they never produce an extra separator. If every entry is empty, or parts has no entries, return "".

Example 1

parts ["a","","b","c"]
sep "-"
returns "a-b-c"

The empty entry is skipped, so a, b and c are joined with a single - between each pair.

Example 2

parts ["","x",""]
sep ", "
returns "x"

Only x is non-empty, so there is nothing to put a separator between.

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