From 4dc777616c2899ace80f68c07b348a65a0b658de Mon Sep 17 00:00:00 2001 From: Cody Loyd Date: Fri, 25 Aug 2017 14:16:42 -0500 Subject: [PATCH] add snakeCase --- README.md | 2 -- snakeCase/README.md | 10 ++++++++++ snakeCase/snakeCase.js | 5 +++++ snakeCase/snakeCase.spec.js | 23 +++++++++++++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 snakeCase/README.md create mode 100644 snakeCase/snakeCase.js create mode 100644 snakeCase/snakeCase.spec.js diff --git a/README.md b/README.md index f1c8359..e37fbb8 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,6 @@ The first exercise, `helloWorld` will walk you through the process in more depth ## planned exercises (in no particular order for the moment): 1. book titles (MC) -1. Palindromes -1. Pangrams 1. pig latin (MC) 1. fibonacci 1. convert to snake case \ No newline at end of file diff --git a/snakeCase/README.md b/snakeCase/README.md new file mode 100644 index 0000000..76bb68b --- /dev/null +++ b/snakeCase/README.md @@ -0,0 +1,10 @@ +# Exercise XX - snakeCase + +Convert phrases and words into snake case + +> Snake case (or snake\_case) is the practice of writing compound words or phrases in which the elements are separated with one underscore character (\_) and no spaces, with each element's initial letter usually lowercased as in "foo\_bar" + +```javascript +snakeCase('Hello, World!') // hello_world +snakeCase('snakeCase') // snake_case +``` \ No newline at end of file diff --git a/snakeCase/snakeCase.js b/snakeCase/snakeCase.js new file mode 100644 index 0000000..d14f180 --- /dev/null +++ b/snakeCase/snakeCase.js @@ -0,0 +1,5 @@ +var snakeCase = function() { + +} + +module.exports = snakeCase diff --git a/snakeCase/snakeCase.spec.js b/snakeCase/snakeCase.spec.js new file mode 100644 index 0000000..7664be0 --- /dev/null +++ b/snakeCase/snakeCase.spec.js @@ -0,0 +1,23 @@ +var snakeCase = require('./snakeCase') + +describe('snakeCase', function() { + it('works with simple lowercased phrases', function() { + expect(snakeCase('hello world')).toEqual('hello_world'); + }); + xit('works with Caps and punctuation', function() { + 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'); + }); + xit('works with camel case', function() { + expect(snakeCase('snakeCase')).toEqual('snake_case'); + }); + xit('works with kebab case', function() { + expect(snakeCase('snake-case')).toEqual('snake_case'); + }); + xit('works with WTF case', function() { + expect(snakeCase('SnAkE..CaSe..Is..AwEsOmE')).toEqual('snake_case_is_awesome'); + }); + +});