Проблем с Car Dealership - JS Advanced Exam - 13 March 2022
Здравейте, получавам 57/100 някой може ли да ми помогне ? Благодаря :)
задача: https://judge.softuni.org/Contests/Practice/Index/3395#1
код :
class CarDealership {
  constructor(name){
    this.name = name
    this.availableCars = []
    this.soldCars = []
    this.totalIncome = 0
  }
  addCar(model, horsePower, price, mileage){
    if(model === 0 || horsePower < 0 || price < 0 || mileage < 0){
       throw new Error('Invalid input!')
    }
    this.availableCars.push({model, horsePower, price, mileage})
    return `New car added: ${model} - ${horsePower} HP - ${mileage.toFixed(2)} km - ${price.toFixed(2)}$`
  }
  sellCar(model, desiredMileage){
    let curr = this.availableCars.find(x => x.model === model)
    if(!curr){
      throw new Error(`${model} was not found!`)
    } else {
      if(curr.mileage <= desiredMileage) curr.price = curr.price
      if((curr.mileage - desiredMileage) === 40000) curr.price *=  0.95
      if((curr.mileage - desiredMileage) > 40000) curr.price *= 0.90
      this.totalIncome += curr.price
    }
    this.availableCars = this.availableCars.filter(x => x !== curr)
    this.soldCars.push(curr)
    return `${model} was sold for ${curr.price.toFixed(2)}$`
  }
  currentCar(){
    if(this.availableCars.length === 0){
      return `There are no available cars`
    } else {
      let result = []
      result.push(`-Available cars:\n`)
      this.availableCars.map(x => {
        result.push(`---${x.model} - ${x.horsePower} HP - ${x.mileage.toFixed(2)} km - ${x.price.toFixed(2)}$\n`)
      })
      return result.join(' ')
    }
  }
  salesReport(criteria){
    if(!criteria === 'horsepower' || !criteria === 'model'){
      throw new Error('Invalid criteria!')
    }
    if(criteria === 'horsepower'){
      this.soldCars.sort((a, b) => b.horsePower - a.horsePower)
    }
    if(criteria === 'model'){
      this.soldCars.sort((a, b) => a.model.localeCompare(b.model))
    }
    let result = []
    this.soldCars.forEach(x => {
        result.push(`---${x.model} - ${x.horsepower} HP - ${(x.price).toFixed(2)}$`);
    })
    return `-${this.name} has a total income of ${this.totalIncome.toFixed(2)}$\n-${this.soldCars.length} cars sold\n${result.join('\n')}`
  }
}
Благодаря!