Created
December 1, 2015 15:40
-
-
Save jluismm2311/9e326855f4f8626f05d5 to your computer and use it in GitHub Desktop.
Complete the function/method so that it takes CamelCase string and returns the string in snake_case notation. Lowercase characters can be numbers. If method gets number, it should return string. Examples: # returns test_controller to_underscore('TestController') # returns movies_and_books to_underscore('MoviesAndBooks') # returns app7_test to_un…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function toUnderscore(string) { | |
return string.toString().replace(/[A-Z]/g,function(element, index){ | |
element = element.toLowerCase(); | |
return index == 0 ? element :'_'+ element | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment