Created
February 7, 2021 02:00
-
-
Save jloescher/62c055ad52b1a073fdab7e69fcc8b67f to your computer and use it in GitHub Desktop.
Convert a phrase to whale talk using function, loops, and arrays.
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
let input = 'Anh yeu em, yeu hon!'; | |
const vowels = ['a', 'e', 'i', 'o', 'u']; | |
resultsArray = []; | |
function whaleTalk(phrase) { | |
const lowerCasePhrase = phrase.toLowerCase(); | |
for (let l = 0; l < lowerCasePhrase.length; l++) { | |
// console.log(lowerCasePhrase[l]); | |
for (let v = 0; v < vowels.length; v++) { | |
if (vowels[v] === lowerCasePhrase[l]) { // whales only use vowels. | |
if (lowerCasePhrase[l] === 'e' || lowerCasePhrase[l] === 'u') { // e's and u's are doubled in whale talk. | |
resultsArray.push(lowerCasePhrase[l], lowerCasePhrase[l]); | |
} else { // all remaining vowels are singular. | |
resultsArray.push(lowerCasePhrase[l]); | |
} | |
} | |
} | |
} | |
console.log(resultsArray.join('')); | |
} | |
whaleTalk(input); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment