6 kyu

From..To..Series #7: from sentence to camelCase. Can you convert it?

182 of 378myjinxin2015

Description:

Description:

Give you a sentence s. It contains some words and separated by spaces. Another arguments is n, its a number(1,2 or 3). You should convert s to camelCase n.

There are three kinds of camelCase:

camelCase 1: The first letter of each word should be capitalized. 
              Except for the first word.

Example: "Hello world"  -->  "helloWorld"

camelCase 2: The last letter of each word should be capitalized. 
              Except for the last word. 

Example: "Hello world"  -->  "hellOworld"

camelCase 3: The first and last letters of each word should be capitalized. 
              Except for the first and lasts letter of sentence. 

Example: "Hello world"  -->  "hellOWorld" 

You can assume that all of the input data is valid. That is: s always be a string; It contains at least two words; Each word contains only letters(a-zA-Z); Each word contains ar least three letters; n always be 1,2 or 3.

Examples

toCamelCase("hello world",1) === "helloWorld"
toCamelCase("hello world",2) === "hellOworld"
toCamelCase("hello world",3) === "hellOWorld"

toCamelCase("Hello world",1) === "helloWorld"

toCamelCase("Each number plus one",1) === "eachNumberPlusOne"
toCamelCase("Each number plus one",2) === "eacHnumbeRpluSone"
toCamelCase("Each number plus one",3) === "eacHNumbeRPluSOne"

Random tests may contains bug(I'm not sure), please test and feedback, thanks ;-)

Puzzles

Stats:

CreatedOct 21, 2016
PublishedOct 21, 2016
Warriors Trained690
Total Skips6
Total Code Submissions1969
Total Times Completed378
JavaScript Completions182
Python Completions178
Ruby Completions37
Total Stars12
% of votes with a positive feedback rating90% of 138
Total "Very Satisfied" Votes115
Total "Somewhat Satisfied" Votes18
Total "Not Satisfied" Votes5
Total Rank Assessments6
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • kazk Avatar
  • maipatana Avatar
  • saudiGuy Avatar
Ad