Skip to content

Instantly share code, notes, and snippets.

@AndriiBozh
Last active December 8, 2022 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AndriiBozh/8f18164734a35a2f90a643ec54a9c7f7 to your computer and use it in GitHub Desktop.
Save AndriiBozh/8f18164734a35a2f90a643ec54a9c7f7 to your computer and use it in GitHub Desktop.
CodeWars: CamelCase Method
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();
@Ulugbekiut
Copy link

good job

@Adibab
Copy link

Adibab commented Oct 30, 2022

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