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

154
Vistas
How to Know if array has same letters as string

so what I have been trying to acheive is that if I iterate over arr and string and if they have the same letters then some action should be perfomed, for example - if ("both string and array have the same letters"){ "some action" }

const word = "hello";

const arr = ["o", "l", "e", "h"];
about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

const word = "hello";
const arr = ["o", "l", "e", "h"];

const uWord = [...new Set(word)].sort().join()
const uArr = [...new Set(arr)].sort().join()

if (uWord === uArr) {
  // do something
}
about 4 years ago · Santiago Trujillo Denunciar

0

Here is with Linear time O(n). Check whether both items has same chars and same chars count.

const isMatch = (arr, word, track = {}) => {
  arr.forEach((char) => (track[char] = (track[char] ?? 0) + 1));
  [...word].forEach((char) => (track[char] = (track[char] ?? 0) - 1));
  return !Object.values(track).some((val) => val < 0);
};


console.log(isMatch(["o", "l", "e", "h"], "hello"));
console.log(isMatch(["o", "l", "e", "h", "l"], "hello"));
console.log(isMatch(["o", "o"], "lo"));

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