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

142
Vistas
Search Array of strings for matching character sequence

I have an array like this

const arr = ["Apple", "Banana", "Cherry", "Orange", "Avocado", "Ananas", "Pineapple];

I need a function that returns an array with all the Elements from arr, that match the given character sequence. The order of the characters is of importance.

Given "ppl" the function should return ["Apple", "Pineapple"].

Given "n" the function should return ["Banana", "Orange", "Ananas", "Pineapple"].

Given "voca" the function shoould return ["Avocado"]

Given "rr" the function should return ["Cherry"], while given a "r" the function should return ["Cherry", "Orange"].

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

It is also possible like this

const arr = ["Apple", "Banana", "Cherry", "Orange", "Avocado", "Ananas", "Pineapple"];

const query = 'pp';

arr.filter(element => element.includes(query));
about 4 years ago · Juan Pablo Isaza Denunciar

0

try this

const arr = ["Apple", "Banana", "Cherry", "Orange", "Avocado", "Ananas", "Pineapple"];


const search = query => arr.filter(s => s.toLowerCase().includes(query))

console.log(search("n"))
console.log(search("ppl"))

about 4 years ago · Juan Pablo Isaza Denunciar

0

It's pretty straight forward using filter function and indexOf

const arr = ["Apple", "Banana", "Cherry", "Orange", "Avocado", "Ananas", "Pineapple"];
const cond = 'ppl'
console.log(arr.filter(x => x.indexOf(cond) > -1 ))

about 4 years ago · Juan Pablo Isaza 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