solutions

This commit is contained in:
Cody Loyd 2017-12-15 13:26:05 -06:00
parent 7facb382ac
commit 02d2ca43f4
2 changed files with 35 additions and 18 deletions

View file

@ -1,5 +1,19 @@
var snakeCase = function() {
const snakeCase = function(string) {
// wtf case
string = string.replace(/\.\./g, " ");
}
// this splits up camelcase IF there are no spaces in the word
if (string.indexOf(" ") < 0) {
string = string.replace(/([A-Z])/g, " $1");
}
module.exports = snakeCase
return string
.trim()
.toLowerCase()
.replace(/[,\?\.]/g, "")
.replace(/\-/g, " ")
.split(" ")
.join("_");
};
module.exports = snakeCase;

View file

@ -1,23 +1,26 @@
var snakeCase = require('./snakeCase')
const snakeCase = require("./snakeCase");
describe('snakeCase', function() {
it('works with simple lowercased phrases', function() {
expect(snakeCase('hello world')).toEqual('hello_world');
describe("snakeCase", () => {
it("works with simple lowercased phrases", () => {
expect(snakeCase("hello world")).toEqual("hello_world");
});
xit('works with Caps and punctuation', function() {
expect(snakeCase('Hello, World???')).toEqual('hello_world');
it("works with Caps and punctuation", () => {
expect(snakeCase("Hello, World???")).toEqual("hello_world");
});
xit('works with longer phrases', function() {
expect(snakeCase('This is the song that never ends....')).toEqual('this_is_the_song_that_never_ends');
it("works with longer phrases", () => {
expect(snakeCase("This is the song that never ends....")).toEqual(
"this_is_the_song_that_never_ends"
);
});
xit('works with camel case', function() {
expect(snakeCase('snakeCase')).toEqual('snake_case');
it("works with camel case", () => {
expect(snakeCase("snakeCase")).toEqual("snake_case");
});
xit('works with kebab case', function() {
expect(snakeCase('snake-case')).toEqual('snake_case');
it("works with kebab case", () => {
expect(snakeCase("snake-case")).toEqual("snake_case");
});
xit('works with WTF case', function() {
expect(snakeCase('SnAkE..CaSe..Is..AwEsOmE')).toEqual('snake_case_is_awesome');
it("works with WTF case", () => {
expect(snakeCase("SnAkE..CaSe..Is..AwEsOmE")).toEqual(
"snake_case_is_awesome"
);
});
});