mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2024-12-08 00:45:29 +01:00
✨ Add "camel-case" challenge
This commit is contained in:
parent
7c9c59e5b1
commit
3d4aa20915
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,2 @@
|
||||
node_modules
|
||||
node_modules
|
||||
.vscode
|
13
challenges/camel-case/README.md
Normal file
13
challenges/camel-case/README.md
Normal file
@ -0,0 +1,13 @@
|
||||
# camel-case
|
||||
|
||||
Created by [@Divlo](https://github.com/Divlo) at 5 July 2020.
|
||||
|
||||
## Instructions :
|
||||
|
||||
Write a simple camelCase function for strings. All words (except the first) must have their first letter capitalized without spaces.
|
||||
|
||||
**Note :** camelCase is the practice of writing phrases such that each word or abbreviation in the middle of the phrase begins with a capital letter, with no intervening spaces or punctuation.
|
||||
|
||||
## Examples :
|
||||
|
||||
See the `input-output.json` file for examples of input/output.
|
18
challenges/camel-case/input-output.json
Normal file
18
challenges/camel-case/input-output.json
Normal file
@ -0,0 +1,18 @@
|
||||
[
|
||||
{
|
||||
"input": ["camel case"],
|
||||
"output": "camelCase"
|
||||
},
|
||||
{
|
||||
"input": ["say hello "],
|
||||
"output": "sayHello"
|
||||
},
|
||||
{
|
||||
"input": [" camel case word "],
|
||||
"output": "camelCaseWord"
|
||||
},
|
||||
{
|
||||
"input": [""],
|
||||
"output": ""
|
||||
}
|
||||
]
|
0
challenges/camel-case/solutions/.gitkeep
Normal file
0
challenges/camel-case/solutions/.gitkeep
Normal file
@ -0,0 +1,4 @@
|
||||
# typescript-camelcase - camel-case
|
||||
|
||||
Programming language : TypeScript
|
||||
Created by [@Divlo](https://github.com/Divlo) at 5 July 2020.
|
@ -0,0 +1,14 @@
|
||||
function solution (string: string) {
|
||||
return string.length === 0
|
||||
? ''
|
||||
: string
|
||||
.trim()
|
||||
.split(' ')
|
||||
.map((word, index) => {
|
||||
if (index === 0) return word
|
||||
return word[0].toUpperCase() + word.slice(1)
|
||||
})
|
||||
.join('')
|
||||
}
|
||||
|
||||
export default solution
|
Loading…
Reference in New Issue
Block a user