Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

134
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda