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

139
Views
matriz de clasificación con múltiples parámetros de clasificación con objeto de estado en React

Tengo una matriz de servicios de locationServices que contiene una matriz de ubicaciones y una matriz de servicios anidados en el estado.

Mi funcionalidad a continuación consiste en crear una nueva matriz, calcular y agregar algunas propiedades adicionales a una instancia de locationService , empujar a la matriz respectiva y luego ordenar la matriz respectiva.

 let locationsWithDistance = [] let locationsWithNeedMatch = [] let locationsWithDistanceAndNeedMatch = [] locationServices?.map((location) => { location['distance'] = calcLocationDistance(location) location['matchesNeed'] = calcNeedMatches(location) locationsWithDistance.push(location) locationsWithNeedMatch.push(location) locationsWithDistanceAndNeedMatch.push(location) locationsWithDistance.sort(function (a, b) { return a.distance - b.distance; }); locationsWithNeedMatch.sort(function (a, b) { return b.matchesNeed - a.matchesNeed; }); locationsWithDistanceAndNeedMatch.sort(function(a, b){ // need to sort by both distance and matches }) })

la primera matriz ordena por distancia, la segunda ordena por coincidencia de necesidad. Para mi tercera matriz, me gustaría ordenar tanto por distancia como por coincidencia. ¿Cómo puedo conseguir esto?

SALIDA DISEÑADA

 [ { location_id: 1, name: 'location 1', matchesNeed: true, distance: 4.7 }, { location_id: 3, name: 'location 3', matchesNeed: true, distance: 9.9 }, { location_id: 4, name: 'location 4', matchesNeed: false, distance: 5.4 }, { location_id: 5, name: 'location 5', matchesNeed: false, distance: 5.8 }, { location_id: 6, name: 'location 6', matchesNeed: false, distance: 8.7 }, ]

la matriz devuelve primero las coincidencias de necesidad si son verdaderas, y la que esté más cerca del usuario, y luego, después de que el resto de las necesidades se devuelvan por distancia más cercana con la necesidad del usuario de false

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!