-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |