Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
match,map,join solution in Clear category for Conversion from CamelCase by Sim0000
import assert from "assert";
function fromCamelCase(name: string): string {
return name.match(/[A-Z][a-z0-9]*/g).map(x => x.toLowerCase()).join('_');
}
console.log('Example:');
console.log(fromCamelCase('MyFunctionName'));
// These "asserts" are used for self-checking
assert.equal(fromCamelCase('MyFunctionName'), 'my_function_name');
assert.equal(fromCamelCase('IPhone'), 'i_phone');
console.log("Coding complete? Click 'Check' to earn cool rewards!");
May 28, 2020