Skip to content

Instantly share code, notes, and snippets.

@arcdev1
Last active May 1, 2016 04:28
Show Gist options
  • Select an option

  • Save arcdev1/14ad1c89ce29bf4b9387b0cb9abda864 to your computer and use it in GitHub Desktop.

Select an option

Save arcdev1/14ad1c89ce29bf4b9387b0cb9abda864 to your computer and use it in GitHub Desktop.
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