diff --git a/.gitignore b/.gitignore index b512c09..55371e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -node_modules \ No newline at end of file +node_modules +.vscode \ No newline at end of file diff --git a/challenges/camel-case/README.md b/challenges/camel-case/README.md new file mode 100644 index 0000000..b3df08f --- /dev/null +++ b/challenges/camel-case/README.md @@ -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. diff --git a/challenges/camel-case/input-output.json b/challenges/camel-case/input-output.json new file mode 100644 index 0000000..a70ea73 --- /dev/null +++ b/challenges/camel-case/input-output.json @@ -0,0 +1,18 @@ +[ + { + "input": ["camel case"], + "output": "camelCase" + }, + { + "input": ["say hello "], + "output": "sayHello" + }, + { + "input": [" camel case word "], + "output": "camelCaseWord" + }, + { + "input": [""], + "output": "" + } +] diff --git a/challenges/camel-case/solutions/.gitkeep b/challenges/camel-case/solutions/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/challenges/camel-case/solutions/typescript-camelcase/README.md b/challenges/camel-case/solutions/typescript-camelcase/README.md new file mode 100644 index 0000000..7560697 --- /dev/null +++ b/challenges/camel-case/solutions/typescript-camelcase/README.md @@ -0,0 +1,4 @@ +# typescript-camelcase - camel-case + +Programming language : TypeScript +Created by [@Divlo](https://github.com/Divlo) at 5 July 2020. diff --git a/challenges/camel-case/solutions/typescript-camelcase/solution.ts b/challenges/camel-case/solutions/typescript-camelcase/solution.ts new file mode 100644 index 0000000..2dff80a --- /dev/null +++ b/challenges/camel-case/solutions/typescript-camelcase/solution.ts @@ -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