To get started:
- Run
npm install - Write your logic in src/pig.ts, aiming to satisfy the test cases.
- Run tests with
npm test(optionally with--watch)- Tests are found here
Pig Latin is a language game where words are altered according to these rules:
-
For words beginning with consonants:
- Take all consonants before the first vowel
- Move them to the end of the word
- Add "ay" to the end
Examples:
"hello" → "ellohay" "creating" → "eatingcray" -
For words beginning with vowels:
- Simply add "way" to the end of the word
Example:
"algorithm" → "algorithmway"
Your job is to implement a function that translates a string to Pig Latin.
- The input string will never be undefined
- Words will never contain numbers
- Each word should be transformed according to the rules above
"clean code is good" → "eanclay odecay isway oodgay"
"unit tests are the way" → "unitway eststay areway ethay ayway"
- Maintain sentence casing in the translated text
- For ALL CAPS words, the suffix should also be in ALL CAPS ("AY"/"WAY")
"Hello World" → "Ellohay Orldway"
"Very sunny outside Today" → "Eryvay unnysay outsideway Odaytay"
"Roses are RED violets are BLUE" → "Osesray areway EDRAY ioletsvay areway UEBLAY"
"The EARTH is DEFinitELY rounD" → "Ethay EARTHWAY isway EFIniteLYDay oundRay"
"One Apple a DAy keEPs the DOCtor AWAY" → "Oneway Appleway away AYday eePSkay ethay OCTorday AWAYWAY"