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) => {
      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
    }
    • 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
    • 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
    • }