Skip to content

Instantly share code, notes, and snippets.

@lumie31
Created June 13, 2022 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lumie31/57deb8ef6dfa0b5d9f4d77cde91efbc3 to your computer and use it in GitHub Desktop.
Save lumie31/57deb8ef6dfa0b5d9f4d77cde91efbc3 to your computer and use it in GitHub Desktop.
Create a loooong teeeext generator that takes in a string and an integer n, and multiplies the vowels in the string by n.
const longText = (str, num) => {
if (typeof str !== 'string') return 'Input must be a valid string'
let newStr = ''
const vowels = ['a', 'e', 'i', 'o', 'u']
for (let char of str) {
if (vowels.includes(char)) {
newStr += char.repeat(num)
} else {
newStr += char
}
}
return newStr
}
// $longText('hello world', 3) --> heeellooo wooorld
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment