Functional Programming
Algorithms
Mathematics
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 500if (speed >= limit + 20 && speed <= limit + 29) return 250if (speed >= limit + 10 && speed <= limit + 19) return 100return 0- return speed >= limit + 30? 500 :
- speed >= limit + 20? 250 :
- speed >= limit + 10? 100 : 0
- }