Skip to content

Commit

Permalink
w15 challenge
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanous committed Apr 14, 2021
1 parent 66e3f04 commit 47b1d0b
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
35 changes: 35 additions & 0 deletions 2021/w15/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Week 15 challenge

Congratulations! You have inheritted a huge legacy code base, and it is a mess! The naming convention is a total chaos.
Variables and functions are named in all sorts of ways. Worst of all - even hybrid naming conventions are there.

You and your colleague decide that it cannot stay that way for longer, and everything must be renamed to camel case.
Your colleague will do the scraping the codebase and collecting all instances of variable & function names.
Your task is to write a function `fixCase` which, given a variable name, in one of the many cases, always returns it renamed to a proper camel case.

Examples:
```
fixCase('one') // returns 'one'
fixCase('ONE') // returns 'one'
fixCase('oneTwoThree') // returns 'oneTwoThree'
fixCase('OneTwoThree') // returns 'oneTwoThree'
fixCase('one-two-three') // returns 'oneTwoThree'
fixCase('one_two_three') // returns 'oneTwoThree'
fixCase('one_Two_three') // returns 'oneTwoThree'
fixCase('one_two-three') // returns 'oneTwoThree'
fixCase('one__two__three') // returns 'oneTwoThree'
fixCase('one--two--three') // returns 'oneTwoThree'
fixCase('one__two--three') // returns 'oneTwoThree'
fixCase('ONE_two_THREE') // returns 'oneTwoThree'
fixCase('ONE_Two--THREE') // returns 'oneTwoThree'
fixCase('ONE_Two--THREE') // returns 'oneTwoThree'
```


## Upload link

[https://forms.gle/R1ephy3ASZdNG8JKA]


## Results

7 changes: 7 additions & 0 deletions 2021/w15/solutions/solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const fixCase = (input) => {
// your code here

return undefined;
};

module.exports = fixCase;
1 change: 1 addition & 0 deletions 2021/w15/test-cases/spec.json

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions 2021/w15/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const fs = require("fs");
const path = require("path");
const spec = require("./test-cases/spec.json");
const solutions = fs.readdirSync(path.resolve(__dirname, "solutions"));

describe.each(solutions)("%s", (filename) => {
const evaluate = require(path.resolve(__dirname, "solutions", filename));
test.each([
['one = one', 'one', 'one'],
['ONE = one', 'ONE', 'one'],
['oneTwoThree = oneTwoThree', 'oneTwoThree', 'oneTwoThree'],
['OneTwoThree = oneTwoThree', 'OneTwoThree', 'oneTwoThree'],
['one-two-three = oneTwoThree', 'one-two-three', 'oneTwoThree'],
['one_two_three = oneTwoThree', 'one_two_three', 'oneTwoThree'],
['one_Two_three = oneTwoThree', 'one_Two_three', 'oneTwoThree'],
['one_two-three = oneTwoThree', 'one_two-three', 'oneTwoThree'],
['one__two__three = oneTwoThree', 'one__two__three', 'oneTwoThree'],
['one--two--three = oneTwoThree', 'one--two--three', 'oneTwoThree'],
['one__two--three = oneTwoThree', 'one__two--three', 'oneTwoThree'],
['ONE_two_THREE = oneTwoThree', 'ONE_two_THREE', 'oneTwoThree'],
['ONE_Two--THREE = oneTwoThree', 'ONE_Two--THREE', 'oneTwoThree'],
['ONE_Two--THREE = oneTwoThree', 'ONE_Two--THREE', 'oneTwoThree'],
])("%s", (expr, input, result) => {
expect(evaluate(input)).toBe(result);
});

test.each(spec)("spec[%#]", ({ inputs, result }) => {
expect(evaluate(...inputs)).toBe(result);
});
});

0 comments on commit 47b1d0b

Please sign in to comment.