Last active
May 1, 2016 04:38
-
-
Save arcdev1/8d982f6ae977efc44e801456d66043d3 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", | |
result = s.replace(/_./g, rep); // do a global search (g) for an "_" followed by a single character (.) and run the rep function each time | |
function rep(v) { | |
return v[1].toUpperCase(); // return the second character of the matched string, uppercased. | |
} | |
console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I got as far as:
function up_case(str2){
return str2.replace(/_./g,'');
}
But, I didn't know you could pass in a function for the new value.