Last active
December 8, 2022 11:21
-
-
Save AndriiBozh/8f18164734a35a2f90a643ec54a9c7f7 to your computer and use it in GitHub Desktop.
CodeWars: CamelCase Method
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
ASSIGNMENT | |
___________________________ | |
Write simple .camelCase method (camel_case function in PHP, CamelCase in C# or camelCase in Java) for strings. | |
All words must have their first letter capitalized without spaces. | |
For instance: | |
"hello case".camelCase() => HelloCase | |
"camel case word".camelCase() => CamelCaseWord | |
___________________________ | |
SOLUTION | |
___________________________ | |
String.prototype.camelCase = function(){ | |
return this.split(' ').map((word) => word.charAt(0).toUpperCase() + word.slice(1)) | |
.join(''); | |
}; | |
'test case'.camelCase(); |
Hi Can I know why did u use "+" sign before slice ? thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
good job