Shift Every Nth Consonant
Scan message and count its consonants (letters other than a e i o u, in either case). Replace every n-th consonant with the next consonant in the alphabet, keeping its case: b becomes c, d becomes f (skipping the vowel e), x becomes y, and z wraps around to b (Z to B). Leave every other character as it is.
shiftEveryNthConsonant("Codesignal", 3) -> "Codetignam"
// consonants: C d s g n l; the 3rd (s) and 6th (l) move on: s -> t, l -> m
shiftEveryNthConsonant("zZ", 1) -> "bB"y counts as a consonant. n >= 1.
Hints
Hint 1
Work with the lowercase alphabet and a set of vowels; the next consonant after a letter is found by stepping forward (wrapping past z to a) until a non-vowel appears.
Hint 2
Keep a running consonant count; the character changes only when count % n === 0.
Topics
Asked at
Sign in to use the assistant — ask what the problem means, get a hint when you're stuck, or have your current work reviewed. Conversations save to your account.