Skip to content

Instantly share code, notes, and snippets.

@asalant
Created October 4, 2012 19:36
Show Gist options
  • Select an option

  • Save asalant/3835891 to your computer and use it in GitHub Desktop.

Select an option

Save asalant/3835891 to your computer and use it in GitHub Desktop.
Alex Piglatin
var assert = require('assert');
function pigLatin(input)
{
var result = input;
result = result.replace(/(\w+)/g, function(match)
{
var firstChar = match.charAt(0),
firstCharCode = firstChar.charCodeAt(0),
rest = match.substr(1)
;
if(firstCharCode >= 65 && firstCharCode < 97)
rest = rest.charAt(0).toUpperCase() + rest.substr(1);
return rest + firstChar.toLowerCase() + 'ay';
});
return result;
}
assert.equal(pigLatin('hello'), 'ellohay');
assert.equal(pigLatin('hello world'), 'ellohay orldway');
assert.equal(pigLatin('Hello World'), 'Ellohay Orldway');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment