-
Notifications
You must be signed in to change notification settings - Fork 0
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
34 additions
and
2 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,12 @@ | ||
## Convert string to camel case | ||
|
||
https://www.codewars.com/kata/517abf86da9663f1d2000003 | ||
|
||
Complete the method/function so that it converts dash/underscore delimited words into camel casing. The first word within the output should be capitalized only if the original word was capitalized (known as Upper Camel Case, also often referred to as Pascal case). The next words should be always capitalized. | ||
|
||
**Examples** | ||
"the-stealth-warrior" gets converted to "theStealthWarrior" | ||
|
||
"The_Stealth_Warrior" gets converted to "TheStealthWarrior" | ||
|
||
"The_Stealth-Warrior" gets converted to "TheStealthWarrior" |
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,10 @@ | ||
import { toCamelCase } from "./index"; | ||
|
||
describe("Tests", () => { | ||
it("example", () => { | ||
expect(toCamelCase("")).toBe(""); | ||
expect(toCamelCase("the_stealth_warrior")).toBe("theStealthWarrior"); | ||
expect(toCamelCase("The-Stealth-Warrior")).toBe("TheStealthWarrior"); | ||
expect(toCamelCase("A-B-C")).toBe("ABC"); | ||
}); | ||
}); |
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,10 @@ | ||
export function toCamelCase(str: string): string { | ||
if (!str.length) { | ||
return ""; | ||
} | ||
|
||
return str | ||
.split(new RegExp("[_\\-]")) | ||
.map((w, index) => (index > 0 ? w[0].toUpperCase() + w.slice(1) : w)) | ||
.join(""); | ||
} |
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