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
los elementos de la matriz no coinciden con los mismos elementos asignados

Escribí una función en la que estoy recorriendo una matriz (que contiene una cantidad de elementos de la matriz).

p.ej

 theMainAr:[ [ 5 ],[ 5, 3 ],[ 5, 3, 9 ],[ 5, 3, 9, 4 ],[ 3 ],[ 3, 9 ],[ 3, 9, 4 ],[ 9 ],[ 9, 4 ],[ 4 ] ]

La matriz principal de la que obtuve la matriz anterior es:

 weights: [5,3,9,4]

Quiero obtener una combinación de estas matrices anteriores como esta:

 sameLenAr:[[5,9],[5,4],[5,3,4],[3,4]]

Pero cada vez que obtengo un resultado como este: [[5,4],[5,4],[5,3,4],[3,4]] El primer elemento no es [5,9] ¿Por qué?

 let theMainAr = [ [ 5 ],[ 5, 3 ],[ 5, 3, 9 ],[ 5, 3, 9, 4 ],[ 3 ],[ 3, 9 ],[ 3, 9, 4 ],[ 9 ],[ 9, 4 ],[ 4 ] ] let weights = [5,3,9,4], lenOfWeights = weights.length; let sameLenAr = [] let inc = 0 for (let i = 1; i < theMainAr.length - 3; i++) { let curLen = theMainAr[i].length if (curLen > 1) { let curAr = theMainAr[i] let curArLen = curAr.length let indexOfEle = weights.indexOf(curAr[curLen - 1]) for (let m = indexOfEle + 1; m < lenOfWeights; m++) { // console.log(a) curAr[curArLen - 1] = weights[m] console.log(curAr) sameLenAr[inc] = curAr inc++ } } } console.log(sameLenAr)

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