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

88
Vistas
Sparse Array HackerRank Exercise

I'm trying to resolve some exercises from hacker rank, and I'm struggling with the array map and filter methods.

This function supposes to search a value from queries array into strings array and when I use the map method it returns an array with undefined values, and when I use the filter method it returns an empty array.

var strings = ['ab','ab','bca','acb']
var queries = ['ab','abc','bc']

function matchingStrings(strings, queries) {
let retArr = []
for(let n = 0; n<queries.length; n++){
       var equalelem = strings.filter(function(queries){queries[n] === [...strings]})
       retArr.push(equalelem.length);
    }
    return equalelem 
}

console.log(matchingStrings(strings, queries))
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Looking only at your syntax, and without analyzing the algorithm, the following things should change:

  • Your filter function always returns undefined. Any function that doesn't have an explicit return statement returns undefined. Maybe you wanted to use an arrow function expression, which doesn't require a return statement if you omit the curly braces?

    var equalelem = strings.filter((queries) => queries[n] === [...strings])
    
  • Inside the filter function, you seem to be comparing an element from list queries to a copy of list strings. Comparing an element of a list (in this case, a single string) to a list will never be true in your case.

  • The variable letArr doesn't seem to serve any purpose.

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