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

159
Views
Intentando agregar cada elemento de la matriz al siguiente para un número desconocido de elementos

Algo así pero generalizado

 let arr = [6, 5, 4, 3]; let i = 0, j = 0; let result = []; result.push(arr[0]+arr[1], arr[2]+arr[3]); console.log(result
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Ignorando el último elemento si la matriz tiene un número impar de elementos:

 function f(arr) { let result = []; for (let i=0; i<arr.length; i++) { if (i % 2==0 && i<arr.length-1) { result.push(arr[i] + arr[i+1]); i++; } }; return result; } let arr = [6, 5, 4, 3]; console.log(f(arr)); console.log(f([1, 2, 3, 4, 5, 6, 7]));

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!