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

109
Views
Iterando sobre una matriz para comprobar si las cadenas ```incluyen``` otra cadena

usando el método includes para verificar si las cadenas en una matriz incluyen otra cadena. Básicamente como un tipo de cosa de función de búsqueda.

Esto es lo que tengo hasta ahora

 this.findIngredient = function(ingredientName) { for (i=0; i < this.ingredients.length; i++) { if (this.ingredients[i].includes(ingredientName)) { return true break } else { return false } } }

lo que no estoy seguro es por qué cuando this.ingredient contiene una cadena que incluye el nombre del ingredientName , todavía genera false .

Para el contexto, esta es la matriz this.ingredient

 this.ingredients = ["500g plain flour", "1 tsp fine salt", "2 heaped tsp baking powder"]
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Quitar el bloque else de tu bucle debería resolver el problema.

Explicación -

El bloque else se ejecuta cuando this.ingredients[i].includes(ingredientName) es false . Y en su código, cuando el bloque else devuelve false , lo que significa que su ciclo no tendrá la oportunidad de verificar cada elemento en la matriz de ingredientes ya que la función detendrá la ejecución cuando vea una declaración de devolución.

about 4 years ago · Santiago Trujillo 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!