FastPrepConvert Snake Case Variables to Camel Case

Convert Snake Case Variables to Camel Case

Ramp logoRamp● EasyFULLTIMENEW GRADOA
Learn

Problem statement

Given a string text containing space-separated variable names written in snake_case, convert every variable name to camelCase and return the resulting string.

For each variable name:

  • Preserve every leading and trailing underscore.
  • Remove each underscore between lowercase words and capitalize the first letter of the following word.
  • Leave a variable name with no internal underscore unchanged.

Keep the variable names in their original order and keep the single spaces between them.

Function

toCamelCase(text: String) → String

Examples

Example 1

text = "__variable_one__ _variable_two variable_three"return = "__variableOne__ _variableTwo variableThree"

The leading and trailing underscores stay in place. The internal underscores are removed, and the letters o and t that follow them become uppercase.

Example 2

text = "foo_bar __hello_world_ plain"return = "fooBar __helloWorld_ plain"

foo_bar becomes fooBar, __hello_world_ becomes __helloWorld_, and plain is unchanged.

Constraints

  • 1 <= text.length <= 10^5.
  • text contains lowercase English letters, underscores, and single spaces.
  • Variable names are separated by exactly one space, with no leading or trailing space.
  • Each variable name contains at least one letter.
  • After removing its leading and trailing underscores, each variable name contains one or more non-empty lowercase words separated by single underscores.

More Ramp problems

See Ramp hiring insights
public String toCamelCase(String text) {
  // Write your code here.
}
text"__variable_one__ _variable_two variable_three"
expected"__variableOne__ _variableTwo variableThree"
Checking account…