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

399
Views
Mostrar rango de precios como '$' dado un mínimo, un máximo y un nuevo precio en Javascript

Estoy trabajando en este proyecto donde hago una oferta de trabajo.

La clase Oferta tiene 4 parámetros (Nombre, Estado, Detalle y Precio). Sin embargo, en mi tabla tengo 5 columnas (Nombre, Estado, Detalle, Precio y Tipo). Donde debo mostrar '$$$$' para que el precio de una oferta sea mayor que el 75% de los valores mínimo y máximo de la matriz (ver más adelante), también debo agregar '$$$', '$$' y '$' (no es un problema).

Cuando agrego la primera oferta, muestra un '-' porque el mínimo y el máximo no pueden ser iguales. Hasta aquí todo bien. El problema es cuando tengo que agregar una segunda, tercera, etc. ofertas, ya que usa el último precio para calcular el porcentaje y esto hace que los tipos de ofertas antiguos calculen mal.

Código:

 tipodeprecio(){ let num = 0; let Tipo = []; for(let i=0; i< this.listaOferta.length; i++){ num = this.listaOferta[i].Precio; Tipo.push(num); } let min = Math.min(...Tipo); let max = Math.max(...Tipo); let dif = max - min; let porcentaje = (num*100)/dif; if(min === max){ return "-"; } else{ if (porcentaje > 75){ return "$$$$"; } else if (porcentaje <= 75 && porcentaje > 50){ return "$$$"; } else if (porcentaje <= 50 && porcentaje > 25){ return "$$"; } else { return "$"; } } }
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!