Skip to content

Instantly share code, notes, and snippets.

@sealucky7
Created December 22, 2018 15:45
Show Gist options
  • Save sealucky7/25b88780afd1c4300b44b6871fdd3aa7 to your computer and use it in GitHub Desktop.
Save sealucky7/25b88780afd1c4300b44b6871fdd3aa7 to your computer and use it in GitHub Desktop.
Напишите функцию camelize(str), которая преобразует строки вида «my-short-string» в «myShortString».
То есть, дефисы удаляются, а все слова после них получают заглавную букву.
-----------------------------------------------------------------------------------------
function camelize(str) {
var strNew = str.split('-');
for(var i = 1; i < strNew.length; i++) {
strNew[i] = strNew[i].charAt(0).toUpperCase() + strNew[i].slice(1);
}
return strNew.join('');
}
console.log(camelize("background-color") === 'backgroundColor');
console.log(camelize("list-style-image") === 'listStyleImage');
console.log(camelize("-webkit-transition") === 'WebkitTransition');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment