How I solved Leetcode Challenge, Remove Vowels from a String!

Danielle Torres
2 min readMay 24, 2021

--

Hello Everyone,

Today I will be reviewing how I solved Leetcode Challenge, Remove Vowels from String.

Objective: Given a string s, remove the vowels ‘a’, ‘e’, ‘i’, ‘o’, and ‘u’ from it, return the new string.

First I began by console logging the string to see what my output looked like. Next, I began creating my variables. stringArray stored my string split into an array (i.e. [‘l’,’e’,’e’,’t’,’c’…]).

Then I created an array to hold the vowels I would be comparing my stringArray to. Last the newStringArray, will store my new string minus the vowels.

I created a for loop that increments through each letter in my stringArray and push the letter into the newStringArray if the letter is not included in my vowels array.

Lastly, I join the newSringArray back together and return the variable.

It passed!

Here is the final code!

var removeVowels = function(s) {

const stringArray = s.split(“”);
const vowels = [‘a’,’e’,’i’,’o’,’u’]
const newStringArray = [];

for (let i =0; i < stringArray.length; i++){

if (vowels.includes(stringArray[i]) !== true) {
newStringArray.push(stringArray[i])
}
};
return newStringArray.join(“”)
};

Please let me know what you think and if this helps you solve your challenge. Until next time!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Danielle Torres
Danielle Torres

Written by Danielle Torres

Highly organized & motivated Software Engineer with an application analyst/data analyst background.

No responses yet