The vowel substrings in the word codewarriors
are o,e,a,io
. The longest of these has a length of 2. Given a lowercase string that has alphabetic characters only and no spaces, return the length of the longest vowel substring. Vowels are any of aeiou
.
Good luck!
This challenge comes from KenKamau at CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (19)
The new JS function
matchAll
is going to be really useful.Here's a JS quickie
Gotta love JavaScript one-liners
Javascript version
Here's mine... would have liked to use
String.prototype.matchAll
, but my JS engine didn't support it. So used a generator andArray.from
instead. :-)Full Gist: gist.github.com/kerrishotts/a3ec30...
Just noticed that the challenge is to return the length ;-) Oh well --
getLongestVowelSequence("codewarriors").length
will do ;-)Haskell
I could have done it with a single fold, but I decided to group the characters by groups of vowels and non-vowels, filter out the groups that are not vowels, map the length of each group and pick the largest number.
Also, almost entirely point-free, a pity I couldn't figure out how to make
bothVowels
point-free.Hi,
this is my first time sharing my code here, so please don't judge :)
But I really like these little challenges, thank you!
Here we go (python ftw!):
There is probably some room for improvement...
Have a nice day!
Hi @heidrichj you could also use the class Counter from collections package :)
Tip:
In golang! Could be simpler but lots of loops!
Go Playground example original
EDIT:
Add new example with changes from comments
Go Playground example with new switch
EDIT 2:
Realized it would not handle vowels at the end of the string
Go Playground
Hey @peter , you can also use multiple values in a single case statement
github.com/golang/go/wiki/Switch#m...
Hey good to know thanks! Just learning go so didn't realize I could do that. Thanks!
there's also
strings.Count
built-in method ;)golang.org/pkg/strings/#Count
Edit: It being python, I'm condensing my previous code down into a list comprehension.
I like your approach!
Javascript with reduce