Created
October 4, 2012 19:36
-
-
Save asalant/3835891 to your computer and use it in GitHub Desktop.
Alex Piglatin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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