CodeMIRAI
0 XP

camelCase to snake_case

Medium +50 XP Solved

Read a variable name written in camelCase and print it in snake_case: lower case, with an underscore before each word that started with a capital.

userFirstName becomes user_first_name.

Input
userFirstName
Expected output
user_first_name
Input
total
Expected output
total
Show a hint

A regular expression /[A-Z]/g finds every capital letter; replace each with an underscore plus its lower-case form.

Show a solution
JavaScript
Loading the editor…
Run the tests to check your solution.