Created
September 8, 2020 20:13
-
-
Save Delni/1a6ad9850bc7ab320e4941b78316d9a8 to your computer and use it in GitHub Desktop.
This file contains 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
const isVowel = (c: string) => 'aeiouy'.includes(c) | |
const yay = (word: string) => word + (isVowel(word[word.length - 1]) ? 'y' : '') + 'ay' | |
const isUpperString = (c: string) => c === c.toUpperCase() | |
const hasUpperCharacter = (word: string) => word.split('').find(isUpperString) | |
const restablishCase = (word: string) => hasUpperCharacter(word) | |
? word[0].toUpperCase() + word.substring(1).toLowerCase() | |
: word; | |
const toPigLatinWord = (word: string) => { | |
const index = word.split('').findIndex(isVowel) | |
return restablishCase(yay(word.substring(index) + word.substring(0, index))) | |
} | |
const toPigLatinSentence = (sentence: string) => sentence.replace(/\w+/g, toPigLatinWord) | |
console.log(toPigLatinSentence('Come to the dark side, we have cookies (and keebs!)')) | |
// Omecay otay ethay arkday idesay, eway avehay ookiescay (anday eebskay!) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment