Ad
Functional Programming
Algorithms
Mathematics
Code
Diff
  • export const checkIfAtOrBelowLimit = (driverSpeeds: number[], speedLimit: number): number[] => {
      return driverSpeeds.map(speed => CalculateFine(speed, speedLimit));
    }
    const CalculateFine = (speed: number, limit: number) => {
      return speed >= limit + 30? 500 : 
        speed >= limit + 20? 250 : 
        speed >= limit + 10? 100 : 0
    }
    • export const checkIfAtOrBelowLimit = (driverSpeeds: number[], speedLimit: number): number[] => {
    • return driverSpeeds.map(speed => CalculateFine(speed, speedLimit));
    • }
    • const CalculateFine = (speed: number, limit: number) => {
    • if(speed >= limit + 30) return 500
    • if (speed >= limit + 20 && speed <= limit + 29) return 250
    • if (speed >= limit + 10 && speed <= limit + 19) return 100
    • return 0
    • return speed >= limit + 30? 500 :
    • speed >= limit + 20? 250 :
    • speed >= limit + 10? 100 : 0
    • }