Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

122
Views
I have to make a function which takes an array of strings and returns an array with only strings that doesn't start with a vowel

Write a function removeVowelKeys, that takes an array of strings keys and returns an array of keys that does not start with a vowel (aeiouy). The letter case does not matter.

Example :

removeVowelKeys(['alarm', 'chip', 'isValid', 'Advice', 'onClick']); // ['chip']

Here is my attmpt this is the max i could get out of it :

    function removeVowelKeys(keys) {
  let result = [];
  for (let i=0;i<=keys.length;i++){
    if (keys[i][0]!= 'a'||keys[i][0]!= 'e'||keys[i][0]!= 'i'||keys[i][0]!= 'o'||keys[i][0]!= 'u'||keys[i][0]!= 'y'){
      result.push(keys[i])
    }
  }
  return result;
}
about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

The problem with this condition is :

if (keys[i][0]!= 'a'||keys[i][0]!= 'e'||keys[i][0]!= 'i'||keys[i][0]!= 'o'||keys[i][0]!= 'u'||keys[i][0]!= 'y')

that it will match for any alphabet. You are doing an OR check. Take for example e and do a dry run. It will psas the first condition. a will pass the second condition. And if any one of the expression is true, the whole expression returns true.

function removeVowelKeys(keys) {
  let result = [];
  for (let i=0;i<keys.length;i++){
    if (keys[i][0].toLowerCase()!= 'a'&&keys[i][0].toLowerCase()!= 'e'&&keys[i][0].toLowerCase()!= 'i'&&keys[i][0].toLowerCase()!= 'o'&&keys[i][0].toLowerCase()!= 'u'&&keys[i][0].toLowerCase()!= 'y'){
      result.push(keys[i])
    }
  }
  return result;
}

console.log(removeVowelKeys(['alarm', 'chip', 'isValid', 'Advice', 'onClick'])); 

Besides that, you want your code to run till i<keys.length. Arrays are 0 based right. And to handle case, you would need to lower case as done above.

about 4 years ago · Santiago Trujillo Report

0

You can filter the array, and on each item check if the item startsWith a vowel character from the array with some method.

const vowelChar = ['a', 'o', 'e', 'i', 'y', 'u']
console.log(removeVowelKeys(['alarm', 'chip', 'isValid', 'Advice', 'onClick']));
// ['chip']
function removeVowelKeys(keys) {
  return keys.filter(item => !vowelChar.some(c => item.toLowerCase().startsWith(c)))
}

about 4 years ago · Santiago Trujillo Report

0

Here is another solution just incase anyone wants to use regex. It still loops through the keys and grabs the first character of each passed argument, but it checks it against the vowels.

function removeVowelKeys(keys) {
  let result = [];
  
  for (let i = 0; i <= keys.length-1; i++) {
     if(!keys[i][0].match(/[aeiuoy]/i)){
       result.push(keys[i])
     }
  }
  return result;
}

console.log(removeVowelKeys(['alarm', 'chip', 'isValid', 'Advice', 'onClick']));

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!