From 3d4aa209152495931016522c4db1518219655df0 Mon Sep 17 00:00:00 2001 From: Divlo Date: Sun, 5 Jul 2020 20:09:17 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20"camel-case"=20challenge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- challenges/camel-case/README.md | 13 +++++++++++++ challenges/camel-case/input-output.json | 18 ++++++++++++++++++ challenges/camel-case/solutions/.gitkeep | 0 .../solutions/typescript-camelcase/README.md | 4 ++++ .../solutions/typescript-camelcase/solution.ts | 14 ++++++++++++++ 6 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 challenges/camel-case/README.md create mode 100644 challenges/camel-case/input-output.json create mode 100644 challenges/camel-case/solutions/.gitkeep create mode 100644 challenges/camel-case/solutions/typescript-camelcase/README.md create mode 100644 challenges/camel-case/solutions/typescript-camelcase/solution.ts 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