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

395
Views
Show price range as '$' given a min, a max and a new price in Javascript

I am working in this project where I do an offer of a job

The class Offer has 4 parameters (Name, State, Detail and Price). However, in my table I have 5 columns (Name, State, Detail, Price and Type). Where I have to show '$$$$' for an offer's price to be bigger than 75% of the min and max values of array (see later), I also have to add '$$$', '$$' and '$' (not a problem).

When I add the first offer it shows a '-' because min and max can't be equal. So far so good. The problem is when I have to add a second, third, etc. offers since it uses the last price to calculate the percentage and this causes old offer types to miscalculate.

Code:

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!