File tree 3 files changed +23
-7
lines changed
3 files changed +23
-7
lines changed Original file line number Diff line number Diff line change 5
5
},
6
6
{
7
7
"arguments" : [" Hello World" ],
8
- "result" : " helloWorld "
8
+ "result" : " HelloWorld "
9
9
},
10
10
{
11
11
"arguments" : [" Hello World " ],
12
- "result" : " helloWorld "
12
+ "result" : " HelloWorld "
13
13
},
14
14
{
15
15
"arguments" : [" Hello World! What is up?" ],
16
- "result" : " helloWorldWhatIsUp "
16
+ "result" : " HelloWorldWhatIsUp "
17
17
},
18
18
{
19
19
"arguments" : [" Hello World ! 123 What is up?" ],
20
- "result" : " helloWorld123WhatIsUp "
20
+ "result" : " HelloWorld123WhatIsUp "
21
21
}
22
22
]
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ const toCamelCase = require('../toCamelCase');
4
4
const expect = require ( 'chai' ) . expect ;
5
5
const testData = require ( './toCamelCase.json' ) ;
6
6
7
- describe ( 'Module 4 - toCamelCase' , ( ) => {
7
+ describe . only ( 'Module 4 - toCamelCase' , ( ) => {
8
8
it ( 'should be a function' , ( ) => {
9
9
expect ( toCamelCase ) . to . be . instanceOf ( Function ) ;
10
10
} ) ;
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
+ const CHARACTERS_TO_KEEP = "0123456789qwertzuiopasdfghjklyxcvbnm" ;
2
3
/**
3
4
* It returns the camel-case version of string.
4
- * E.g.: simple lowercase string => Simple Lowercase String
5
+ * E.g.: simple lowercase string => SimpleLowercaseString
5
6
*
6
7
* @param {string } toConvert
7
8
* @returns {string } camel-case string or empty string in other cases
8
- */
9
+ */
10
+ function toCamelCase ( toConvert ) {
11
+ if ( typeof toConvert !== 'string' ) {
12
+ return '' ;
13
+ }
14
+ return toConvert
15
+ . split ( ' ' )
16
+ . map ( word => word
17
+ . split ( '' )
18
+ . filter ( char => CHARACTERS_TO_KEEP . indexOf ( char . toLocaleLowerCase ( ) ) !== - 1 )
19
+ . join ( '' )
20
+ )
21
+ . map ( word => word . charAt ( 0 ) . toLocaleUpperCase ( ) + word . substr ( 1 ) . toLocaleLowerCase ( ) )
22
+ . join ( '' ) ;
23
+ }
24
+ module . exports = toCamelCase ;
You can’t perform that action at this time.
0 commit comments