Created
December 22, 2018 15:45
-
-
Save sealucky7/25b88780afd1c4300b44b6871fdd3aa7 to your computer and use it in GitHub Desktop.
This file contains 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
Напишите функцию 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