Convert camelCase to snake_case

Published by silviaf in

Create a function that takes a string of words (or just one word) and converts each word from camelCase to snake_case.

Examples

camelToSnake("magicCarrots") ➞ "magic_carrots"

camelToSnake("greatApples for aSmellyRhino") ➞ "great_apples for a_smelly_rhino"

camelToSnake("thatsGreat") ➞ "thats_great"

Notes

You won't get more than two capitals in a row (e.g. "DIYFoods" is not given).

Watch a quick demo on how Edabit works.