JavaScript Using RegEx
Rutik Bhoyar
Posted on December 11, 2021
Problem:
Return the number (count) of vowels in the given string.
We will consider a, e, i, o, u as vowels.
The input can consist of Lower case and upper case letters so make sure to count both of them
function getCount(str) {
return str.match(/[aeiou]/gi).length
}
This will give you the count of vowels in javascript.
Stop gninnipS My sdroW!
Problem:
Write a function that takes in a string of one or more words, and returns the same string, but with all five or more letter words reversed (Just like the name of this Kata). Strings passed in will consist of only letters and spaces. Spaces will be included only when more than one word is present.
function spinWords(string) {
return string.replace(/\w{5,}/g,
function(w) {return w.split('').reverse().join('')}
)
}
This will be give correct output like below.
spinWords(“Hey fellow warriors”) //returns “Hey wollef sroirraw"
spinWords("This is a test") //returns "This is a test"
spinWords("This is another test") //returns "This is rehtona test"
💖 💪 🙅 🚩
Rutik Bhoyar
Posted on December 11, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.