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

228
Views
Cómo multiplicar cada valor en una matriz de coordenadas

Tengo una matriz de coordenadas:

 const markerCoords = [ { topLeftX: 68.5, topLeftY: 19 }, { topLeftX: 57.5, topLeftY: 57.5 }, { topLeftX: 140.5, topLeftY: 52 }, { topLeftX: 136, topLeftY: 70 }, { topLeftX: 134.3, topLeftY: 88.3 }, { topLeftX: 270.5, topLeftY: 68.8 }, { topLeftX: 211.7, topLeftY: 135.3 }, { topLeftX: 245.5, topLeftY: 189.7 }, { topLeftX: 199.5, topLeftY: 222.5 }, { topLeftX: 128.5, topLeftY: 241.6 }, { topLeftX: 174.3, topLeftY: 263.5 }, { topLeftX: 167.8, topLeftY: 285.7 }, { topLeftX: 134, topLeftY: 309 }, { topLeftX: 251, topLeftY: 304.6 }];

Y quiero multiplicar cada valor por x y asignar las nuevas coordenadas a una nueva matriz similar. Al igual que:

 const newMarkerCoords = markerCoords.map({topLeftX, topLeftY} => {topLeftX * x, topLeftY * x})

Es para colocar marcadores en los lugares correctos, cuando amplío el mapa de la imagen.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Esto es probablemente lo que quieres:

 const newMarkerCoords = markerCoords.map(item => {return {topLeftX:item.topLeftX*x, topLeftY:item.topLeftY*x};})
about 4 years ago · Juan Pablo Isaza Report

0

Estuvo bastante cerca, aquí hay una muestra funcional de lo que intentó hacer:

 const markerCoords = [ { topLeftX: 68.5, topLeftY: 19 }, { topLeftX: 57.5, topLeftY: 57.5 }, { topLeftX: 140.5, topLeftY: 52 }, { topLeftX: 136, topLeftY: 70 }, { topLeftX: 134.3, topLeftY: 88.3 }, { topLeftX: 270.5, topLeftY: 68.8 }, { topLeftX: 211.7, topLeftY: 135.3 }, { topLeftX: 245.5, topLeftY: 189.7 }, { topLeftX: 199.5, topLeftY: 222.5 }, { topLeftX: 128.5, topLeftY: 241.6 }, { topLeftX: 174.3, topLeftY: 263.5 }, { topLeftX: 167.8, topLeftY: 285.7 }, { topLeftX: 134, topLeftY: 309 }, { topLeftX: 251, topLeftY: 304.6 }]; const x = 2; newMarkerCoords = markerCoords.map(({topLeftY, topLeftX}) => {return {topLeftY: topLeftY * x, topLeftX: topLeftX * x}}) console.log(newMarkerCoords);

about 4 years ago · Juan Pablo Isaza Report

0

Creo que este es el problema con tu código:

 const markerCoords = [ { topLeftX: 68.5, topLeftY: 19 }, { topLeftX: 57.5, topLeftY: 57.5 }, { topLeftX: 140.5, topLeftY: 52 }, { topLeftX: 136, topLeftY: 70 }, { topLeftX: 134.3, topLeftY: 88.3 }, { topLeftX: 270.5, topLeftY: 68.8 }, { topLeftX: 211.7, topLeftY: 135.3 }, { topLeftX: 245.5, topLeftY: 189.7 }, { topLeftX: 199.5, topLeftY: 222.5 }, { topLeftX: 128.5, topLeftY: 241.6 }, { topLeftX: 174.3, topLeftY: 263.5 }, { topLeftX: 167.8, topLeftY: 285.7 }, { topLeftX: 134, topLeftY: 309 }, { topLeftX: 251, topLeftY: 304.6 }]; let newMarkerCoords = markerCoords.map(({topLeftY, topLeftX}) => { return {topLeftY: topLeftY * 2, topLeftX: topLeftX * 2} }); console.log(newMarkerCoords);

No regresaba correctamente de la función de mapa, las llaves hacen el cuerpo de la función, pero no devolvía nada.

 const markerCoords = [ { topLeftX: 68.5, topLeftY: 19 }, { topLeftX: 57.5, topLeftY: 57.5 }, { topLeftX: 140.5, topLeftY: 52 }, { topLeftX: 136, topLeftY: 70 }, { topLeftX: 134.3, topLeftY: 88.3 }, { topLeftX: 270.5, topLeftY: 68.8 }, { topLeftX: 211.7, topLeftY: 135.3 }, { topLeftX: 245.5, topLeftY: 189.7 }, { topLeftX: 199.5, topLeftY: 222.5 }, { topLeftX: 128.5, topLeftY: 241.6 }, { topLeftX: 174.3, topLeftY: 263.5 }, { topLeftX: 167.8, topLeftY: 285.7 }, { topLeftX: 134, topLeftY: 309 }, { topLeftX: 251, topLeftY: 304.6 }]; let newMarkerCoords = markerCoords.map(({topLeftY, topLeftX}) => Object.assign({}, {topLeftY: topLeftY * 2, topLeftX: topLeftX * 2})); console.log(newMarkerCoords);

Puedes hacer algo así.

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!