Last active
May 1, 2016 04:28
-
-
Save arcdev1/14ad1c89ce29bf4b9387b0cb9abda864 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| var s = "some_string_to_change", | |
| len= s.length, | |
| i, | |
| upped = false; // we will use this to make sure we don't double count a character | |
| result = ""; // this is where we will store the result | |
| for(i=0;i<len;i++) { | |
| if(s[i] === "_") { // if we find an underscore | |
| result += s[i+1].toUpperCase(); // add the next character, uppercased, to our result | |
| upped = true; // make sure we don't add this character again | |
| } else if (upped === false) { // skip any characters we've added. | |
| result += s[i]; // add the current character to our result | |
| } else { | |
| upped = false; // reset the flag so we can carry on | |
| } | |
| } | |
| console.log(result) // output the result to the console. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment