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

119
Views
Necesito verificar si el primer número de la matriz es igual al último

tengo una matriz

 const array = [[1, 2], [3, 3]]; arr.forEach(el => { if (el[0] === el[1]) {return true} })
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

No tiene sentido volver verdadero en un forEach

Supongo que te refieres a esto:

 const testArr = arr => arr[0] === arr[arr.length-1]; // test first and last const array = [[1, 2], [3, 3]]; const testResults = array.map(el => testArr(el)); // map the results console.log(testResults) // filter: const same = array.filter(el => testArr(el)); // FIND the array that has same first and last console.log(same.flat())

about 4 years ago · Juan Pablo Isaza Report

0

Deberías every las funciones

 const arr = [[1, 2], [3, 3]]; const b = arr.every(el => el[0] === el[1]); console.log(b); // false
about 4 years ago · Juan Pablo Isaza Report

0

Esto debería obtener el resultado deseado. Simplemente cambie console.log(true) a lo que quiera hacer si son iguales. Esto funcionará en cualquier longitud de matriz.

 const array = [ [1, 2], [3, 3], ]; array.forEach((el) => { if (el[0] === el[el.length - 1]) { console.log(true); } });
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!