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

88
Views
Problema con el registro de cosas desde una matriz

tengo un problema con el registro de algo de una matriz. Necesito encontrar las ubicaciones mejor calificadas de cada lugar y necesito registrar el nombre y las coordenadas de esas 3 ubicaciones. He estado atrapado aquí por un tiempo ahora, ¿alguien sabe cómo hacer esto?

este es el código que ya tengo:

 let locaties = [ {naam: 'locatie1', type: 'cafe', rating: 8, coordinaat: {lat: 17, lon: 3},}, {naam: 'locatie2', type: 'winkel', rating: 3, coordinaat: {lat: 23, lon: 9},}, {naam: 'locatie3', type: 'Restaurant', rating: 7, coordinaat: {lat: 3, lon: 17},}, {naam: 'locatie4', type: 'winkel', rating: 7, cordinaat: {lat: 20, lon: 10},}, {naam: 'locatie5', type: 'cafe', rating: 1, coordinaat: {lat: 12, lon: 13},}, {naam: 'locatie6', type: 'winkel', rating: 5, coordinaat: {lat: 13, lon: 2},}, {naam: 'locatie7', type: 'Restaurant', rating: 6, coordinaat: {lat: 7, lon: 17},}, {naam: 'locatie8', type: 'Restaurant', rating: 2, cordinaat: {lat: 3, lon: 15},}, {naam: 'locatie9', type: 'cafe', rating: 4, coordinaat: {lat: 30, lon: 12},}, {naam: 'locatie10', type: 'winkel', rating: 9, cordinaat: {lat: 27, lon: 19},}, ]; Object.keys(locaties).forEach(key => { console.log(key); console.log(locaties[key].naam); })
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

 let locations = [{ name: 'locatie1', type: 'cafe', rating: 8, coordinate: { lat: 17, lon: 3 }, }, { name: 'locatie2', type: 'winkel', rating: 3, coordinate: { lat: 23, lon: 9 }, }, { name: 'locatie3', type: 'Restaurant', rating: 7, coordinate: { lat: 3, lon: 17 }, }, { name: 'locatie4', type: 'winkel', rating: 7, coordinate: { lat: 20, lon: 10 }, }, { name: 'locatie5', type: 'cafe', rating: 1, coordinate: { lat: 12, lon: 13 }, }, { name: 'locatie6', type: 'winkel', rating: 5, coordinate: { lat: 13, lon: 2 }, }, { name: 'locatie7', type: 'Restaurant', rating: 6, coordinate: { lat: 7, lon: 17 }, }, { name: 'locatie8', type: 'Restaurant', rating: 2, coordinate: { lat: 3, lon: 15 }, }, { name: 'locatie9', type: 'cafe', rating: 4, coordinate: { lat: 30, lon: 12 }, }, { name: 'locatie10', type: 'winkel', rating: 9, coordinate: { lat: 27, lon: 19 }, }, ]; highest_rated_locations = locations .sort((a, b) => b.rating - a.rating) // order elements by rating descending. Note: the original locations array changes, since the sort method is mutable, if the original array shouldn't be changed, use Array.from .slice(0, 3) // return the first three elements of the array for (const location of highest_rated_locations) { console.log(`Name: ${location.name} | Lattitude: ${location.coordinate.lat} | Longitude: ${location.coordinate.lon}`) }

Ajusté algunos nombres en el código para una mejor comprensión. Para alguna explicación, Object.keys() devuelve todas las claves del Objeto dado. En su caso, se trata de una matriz y los valores serán 0, 1, 2, ... . Si hiciera esto con uno de los objetos dentro de la matriz, por ejemplo Object.keys(locations[0]) , obtendría lo siguiente: name, type, rating, coordinate . lat y lan no estarán allí ya que son propiedades anidadas de coordinate . Le sugiero que se informe un poco sobre los bucles de javascript, ya que son bastante importantes.

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!