Skip to content

Instantly share code, notes, and snippets.

@lrvick
Created April 30, 2014 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lrvick/d634353231d61ce898de to your computer and use it in GitHub Desktop.
Save lrvick/d634353231d61ce898de to your computer and use it in GitHub Desktop.
Pig Latin Translator / Mocha example
var assert = require("assert")
var pigLatinTrans = function(text){
var pigText = text.replace(/[A-Za-z]+/gi,function(word){
var letters = word.split('')
var firstLetter = letters.shift()
if (firstLetter.toUpperCase() == firstLetter){
letters.push(firstLetter.toLowerCase())
letters[0] = letters[0].toUpperCase()
letters.push(firstLetter)
}
return letters.join('') + 'ay'
})
return pigText
}
describe("PigLatinTrans",function(){
describe("pigLatinTrans",function(){
it('can take phrase "hello" and see it translated to Pig Latin "ellohay"',function(){
assert.equal(pigLatinTrans("hello"),"ellohay")
})
it('can take phrase "hello world" and see it translated to Pig Latin "ellohay orldway"',function(){
assert.equal(pigLatinTrans("hello world"),"ellohay orldway")
})
it('can take phrase "Hello world" and see it translated to Pig Latin "Ellohay orldway"', function(){
assert.equal(pigLatinTrans("Hello world"),"Ellohay orldway")
})
it('can take phrase "Hello, world!!" and see it translated to Pig Latin "Ellohay, orldway!!"', function(){
assert.equal(pigLatinTrans("Hello, world!!"),"Ellohay, orldway!!")
})
it('can take phrase "eat apples" and see it translated to Pig Latin "eatay applesay"')
it('can take phrase "quick brown fox" and see it translated to Pig Latin "ickquay ownbray oxfay"')
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment