Skip to content

Commit 02d2ca4

Browse files
committed
solutions
1 parent 7facb38 commit 02d2ca4

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

snakeCase/snakeCase.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1-
var snakeCase = function() {
1+
const snakeCase = function(string) {
2+
// wtf case
3+
string = string.replace(/\.\./g, " ");
24

3-
}
5+
// this splits up camelcase IF there are no spaces in the word
6+
if (string.indexOf(" ") < 0) {
7+
string = string.replace(/([A-Z])/g, " $1");
8+
}
49

5-
module.exports = snakeCase
10+
return string
11+
.trim()
12+
.toLowerCase()
13+
.replace(/[,\?\.]/g, "")
14+
.replace(/\-/g, " ")
15+
.split(" ")
16+
.join("_");
17+
};
18+
19+
module.exports = snakeCase;

snakeCase/snakeCase.spec.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
var snakeCase = require('./snakeCase')
1+
const snakeCase = require("./snakeCase");
22

3-
describe('snakeCase', function() {
4-
it('works with simple lowercased phrases', function() {
5-
expect(snakeCase('hello world')).toEqual('hello_world');
3+
describe("snakeCase", () => {
4+
it("works with simple lowercased phrases", () => {
5+
expect(snakeCase("hello world")).toEqual("hello_world");
66
});
7-
xit('works with Caps and punctuation', function() {
8-
expect(snakeCase('Hello, World???')).toEqual('hello_world');
7+
it("works with Caps and punctuation", () => {
8+
expect(snakeCase("Hello, World???")).toEqual("hello_world");
99
});
10-
xit('works with longer phrases', function() {
11-
expect(snakeCase('This is the song that never ends....')).toEqual('this_is_the_song_that_never_ends');
10+
it("works with longer phrases", () => {
11+
expect(snakeCase("This is the song that never ends....")).toEqual(
12+
"this_is_the_song_that_never_ends"
13+
);
1214
});
13-
xit('works with camel case', function() {
14-
expect(snakeCase('snakeCase')).toEqual('snake_case');
15+
it("works with camel case", () => {
16+
expect(snakeCase("snakeCase")).toEqual("snake_case");
1517
});
16-
xit('works with kebab case', function() {
17-
expect(snakeCase('snake-case')).toEqual('snake_case');
18+
it("works with kebab case", () => {
19+
expect(snakeCase("snake-case")).toEqual("snake_case");
1820
});
19-
xit('works with WTF case', function() {
20-
expect(snakeCase('SnAkE..CaSe..Is..AwEsOmE')).toEqual('snake_case_is_awesome');
21+
it("works with WTF case", () => {
22+
expect(snakeCase("SnAkE..CaSe..Is..AwEsOmE")).toEqual(
23+
"snake_case_is_awesome"
24+
);
2125
});
22-
2326
});

0 commit comments

Comments
 (0)