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

183
Views
¿Cómo probar si una matriz contiene algún valor de otra matriz usando Jest?

tengo una matriz:

 Const domesticAnimals = ['Chicken','lama','Donkey'] Const wildAnimals =['lama','lion','elephant']

¿Cómo compruebo si algún wildAnimals aparece en la matriz de domesticAnimals ?

Yo he tratado

 test('test If any wild animal is in the domestic animal list', async() =>{ expect(domesticAnimals ).toContain('lama') }) //works perfectly test('test If any wild animal is in the domestic animal list', async() =>{ expect(domesticAnimals ).toContain(wildAnimals) // does not work })
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

En realidad tienes DOS arreglos:

 const domesticAnimals = ['Chicken','lama','Donkey']; const wildAnimals =['lama','lion','elephant'];

La forma simple de JS de probar si una matriz contiene valores de la otra sería:

 domesticAnimals.some(domesticAnimal => wildAnimals.includes(domesticAnimal));

Entonces, para poner esto en una prueba, sería:

 test('test If any wild animal is in the domestic animal list', () =>{ expect(domesticAnimals.some( domesticAnimal => wildAnimals.includes(domesticAnimal) )).toBe(true); });

Como nota al margen, marcó las funciones de prueba como async pero en realidad no await nada, por lo que la async es redundante.

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