curriculum/challenges/english/blocks/daily-coding-challenges-javascript/6821ebd4237de8297eaee791.md
Given a string, return its camel case version using the following rules:
), dash (-), or underscore (_). Treat any sequence of these as a word break.toCamelCase("hello world") should return "helloWorld".
assert.equal(toCamelCase("hello world"), "helloWorld");
toCamelCase("HELLO WORLD") should return "helloWorld".
assert.equal(toCamelCase("HELLO WORLD"), "helloWorld");
toCamelCase("secret agent-X") should return "secretAgentX".
assert.equal(toCamelCase("secret agent-X"), "secretAgentX");
toCamelCase("FREE cODE cAMP") should return "freeCodeCamp".
assert.equal(toCamelCase("FREE cODE cAMP"), "freeCodeCamp");
toCamelCase("ye old-_-sea faring_buccaneer_-_with a - peg__leg----and a_parrot_ _named- _squawk") should return "yeOldSeaFaringBuccaneerWithAPegLegAndAParrotNamedSquawk".
assert.equal(toCamelCase("ye old-_-sea faring_buccaneer_-_with a - peg__leg----and a_parrot_ _named- _squawk"), "yeOldSeaFaringBuccaneerWithAPegLegAndAParrotNamedSquawk");
function toCamelCase(s) {
return s;
}
function toCamelCase(s) {
const words = s.replace(/[_\- ]+/g, ' ').split(' ');
return words.map((word, i) => {
if (i === 0) {
return word.toLowerCase();
} else {
const tempWord = word.split('');
return tempWord.shift().toUpperCase() + tempWord.join('').toLowerCase();
}
}).join('')
}