# The Devowelizer Coding Exercise

**URL:** <https://forum.kirupa.com/t/the-devowelizer-coding-exercise/360797>\
**Category:** programming\
**Created:** [November 25, 2014, 1:34am UTC](https://forum.kirupa.com/t/the-devowelizer-coding-exercise/360797 "2014-11-25T01:34:22Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [November 25, 2014, 1:34am UTC](https://forum.kirupa.com/t/the-devowelizer-coding-exercise/360797/1 "2014-11-25T01:34:23Z")

</div>

This is a companion discussion topic for the original entry at [http://www.kirupa.com/html5/the\_devowelizer.htm](http://www.kirupa.com/html5/the_devowelizer.htm)

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [November 7, 2013, 5:01am UTC](https://forum.kirupa.com/t/the-devowelizer-coding-exercise/360797/2 "2013-11-07T05:01:29Z")

</div>

Something new I want to try outside of the usual deconstructions I provide. How about simple challenges that test one’s understanding of certain concepts. The first one is what I describe as [The Devowelizer](http://www.kirupa.com/html5/the_devowelizer.htm). Basically, this function removes any and all vowels from a string and returns the devowelized version.

Here is the solution I described in this article:

```auto
function devowelize(word) {
  let devowelizedWord = "";

  for (let i = 0; i < word.length; i++) {
    let character = word[i].toLowerCase();

    if (isVowel(character) == false) {
      devowelizedWord += character;
    }
  }
  return devowelizedWord;
}

alert(devowelize("Kirupa Chinnathambi"));

function isVowel(char) {
  return char == 'a' ||
    char == 'e' ||
    char == 'i' ||
    char == 'o' ||
    char == 'u' ||
    false;
}

```

Do any of you have an alternate solution you would propose?

Cheers!  
Kirupa 🌀

---

<div class="post-metadata">

**Author:** ![REB\_412](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/reb_412/32/9233_2.png) [@REB\_412](https://forum.kirupa.com/u/REB_412)\
**Post date:** [October 9, 2019, 6:43pm UTC](https://forum.kirupa.com/t/the-devowelizer-coding-exercise/360797/3 "2019-10-09T18:43:03Z")

</div>

I would use the following:

```auto
function devowelize(word) {
	let testPattern = /a|e|i|o|u|/gi;
	return word.replace(testPattern,'');
}

```

Also in the above code should not the line  
`var character = word*`  
be  
`var character = word[i]`

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [October 9, 2019, 6:45pm UTC](https://forum.kirupa.com/t/the-devowelizer-coding-exercise/360797/4 "2019-10-09T18:45:42Z")

</div>

you’re missing isVowel (unless maybe I missed it before because it was being defined before the call (yay hoisting!) and you had to scroll to see it) and something is up with `word*` in your loop

Edit: @kirupa I fixed your original code (re: word\*) based on the code in the link

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [October 9, 2019, 6:48pm UTC](https://forum.kirupa.com/t/the-devowelizer-coding-exercise/360797/5 "2019-10-09T18:48:42Z")

</div>

For the vowel list, you can use a character set: `/[aeiou]/gi`

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [October 9, 2019, 7:08pm UTC](https://forum.kirupa.com/t/the-devowelizer-coding-exercise/360797/6 "2019-10-09T19:08:04Z")

</div>

If you didn’t know, strings are iterables and can be spread with the spread (`...`) syntax.

```javascript
console.log([..."Kirupa Chinnathambi"])
// ["K", "i", "r", "u", "p", "a", " ", "C", "h", "i", "n", "n", "a", "t", "h", "a", "m", "b", "i"]

```

What if we overrode that behavior with a devowelizer?

```javascript
String.prototype[Symbol.iterator] = function * () {
  const vowels = 'aeiou'
  for (const char of this.split('')) {
    if (!vowels.includes(char.toLowerCase())) {
      yield char
    }
  }
}
console.log([..."Kirupa Chinnathambi"])
// ["K", "r", "p", " ", "C", "h", "n", "n", "t", "h", "m", "b"]

```

:-o

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [October 9, 2019, 7:30pm UTC](https://forum.kirupa.com/t/the-devowelizer-coding-exercise/360797/7 "2019-10-09T19:30:11Z")

</div>

Leave it to senocular for the most esoteric yet brilliant solution.

PS None of you remove the y from thyme…

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [October 9, 2019, 8:01pm UTC](https://forum.kirupa.com/t/the-devowelizer-coding-exercise/360797/8 "2019-10-09T20:01:26Z")

</div>

> [@TheCanadian](#):
>
> PS None of you remove the y from thyme…

I almost worked in a randomized-also-remove-y feature to handle the “sometimes y” rule, but didn’t want to overcomplicate things 😉

---

<div class="post-metadata">

**Author:** ![REB\_412](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/reb_412/32/9233_2.png) [@REB\_412](https://forum.kirupa.com/u/REB_412)\
**Post date:** [October 9, 2019, 9:09pm UTC](https://forum.kirupa.com/t/the-devowelizer-coding-exercise/360797/9 "2019-10-09T21:09:43Z")

</div>

Thank you for the clarification. With it, the function reduces to just a single line:  
return word.replace(/[aeiou]/gi,’’)

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [October 10, 2019, 3:46am UTC](https://forum.kirupa.com/t/the-devowelizer-coding-exercise/360797/10 "2019-10-10T03:46:02Z")

</div>

Thanks for noticing the bug in my code @REB_412 and @senocular! Not sure what happened there - must have been a weird copy/paste issue?

It’s funny (to me, at least!) for how this thread (from 2013) got bumped up today. I was fixing some broken links, stumbled upon my original post, and noticed that the :cyclops: smiley from 2013 no longer worked. I edited the post with the closest smiley that started with :cy and ended up with the cyclone. That edit bumped this thread to the top and you all did some great things with it since haha.

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [October 10, 2019, 3:49am UTC](https://forum.kirupa.com/t/the-devowelizer-coding-exercise/360797/11 "2019-10-10T03:49:00Z")

</div>

My minimal-effort Swift version, without trying to be efficient:

```auto
extension String {
    var devowelized: Self {
        filter { !"aeiou".contains($0.lowercased()) }
    }
}

"the quick brown fox jumps over the lazy dog.".devowelized
// th qck brwn fx jmps vr th lzy dg.

```

Turns out that Unicode doesn’t have anything special to say about vowels, so there’s nothing in [`Unicode.Scalar.Properties`](https://developer.apple.com/documentation/swift/unicode/scalar/properties) to help avoid manually writing out the list of English vowels, or generalize over other languages if they have the concept of vowels.

---

<div class="post-metadata">

**Author:** ![abergquist](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/abergquist/32/12871_2.png) [@abergquist](https://forum.kirupa.com/u/abergquist)\
**Post date:** [October 13, 2019, 4:38am UTC](https://forum.kirupa.com/t/the-devowelizer-coding-exercise/360797/12 "2019-10-13T04:38:41Z")

</div>

Since the code issue has been solved, here’s something you can share at your next cocktail party:

- “abstemious” and “facetious” are the only 2 words in the English language that contain all 5 vowels appearing once and in order
- if “y” is also considered a vowel, then “abstemiously” and “facetiously” are the only 2 words in the English language that contain all 6 vowels appearing once and in order

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [October 5, 2022, 9:31pm UTC](https://forum.kirupa.com/t/the-devowelizer-coding-exercise/360797/13 "2022-10-05T21:31:13Z")

</div>

@REB_412 , @abergquist , @senocular , @krilnon , @steve.mills - you all have retroactively been granted the Devowelizer badge for having completed this exercise 😛

I’m nearly done converting [all old exercises](https://www.kirupa.com/codingexercises/index.htm) into badge-able activities!

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [October 18, 2022, 2:22pm UTC](https://forum.kirupa.com/t/the-devowelizer-coding-exercise/360797/14 "2022-10-18T14:22:11Z")

</div>

Just had to go with the regex…

```auto
TheDEVOWELIZER = function(TAKEMYVOWELS) {
  gsub("[aeiou]", "", TAKEMYVOWELS, ignore.case = T)
}

TheDEVOWELIZER("Kirupa Chinnathambi jumps over the lazy dog.")

```

> **[The Devowelizer (R) - myCompiler](https://www.mycompiler.io/view/CjscyfpXKOP)**

---

<div class="post-metadata">

**Author:** ![PAEz](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/paez/32/19607_2.png) [@PAEz](https://forum.kirupa.com/u/PAEz)\
**Post date:** [January 26, 2023, 8:20am UTC](https://forum.kirupa.com/t/the-devowelizer-coding-exercise/360797/15 "2023-01-26T08:20:53Z")

</div>

Here’s another one…

```auto
  let devowelize = (str) => [...str].filter(letter => !'iouae😜'.includes(letter.toLowerCase())).join('');
  console.log(devowelize("Kirupa Chinnathambi😜"));
> Krp Chnnthmb

```

One of the advantages of this method is as you can see here it can handle unicode stuff thanks to the […str] and includes. So you can use it to strip all my stupid smiley faces that I use to often 😜

And if we try the same thing with the old code…

```auto
  function devowelizer(word) {
    let devowelizedWord = "";

    for (let i = 0; i < word.length; i++) {
      let character = word[i].toLowerCase();

      if (isVowel(character) == false) {
        devowelizedWord += character;
      }
    }
    return devowelizedWord;
  }

  function isVowel(char) {
    return char == 'a' ||
      char == '😜' ||
      char == 'e' ||
      char == 'i' ||
      char == 'o' ||
      char == 'u' ||
      false;
  }

  console.log(devowelizer("Kirupa Chinnatha😜mbi"));
> krp chnnth😜mb

```

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [January 26, 2023, 5:32pm UTC](https://forum.kirupa.com/t/the-devowelizer-coding-exercise/360797/16 "2023-01-26T17:32:36Z")

</div>

Nicely done! 🙂
