MCPcopy
hub / github.com/adrianhajdin/project_next13_car_showcase / calculateCarRent

Function calculateCarRent

utils/index.ts:3–16  ·  view source on GitHub ↗
(city_mpg: number, year: number)

Source from the content-addressed store, hash-verified

1import { CarProps, FilterProps } from "@types";
2
3export const calculateCarRent = (city_mpg: number, year: number) => {
4 const basePricePerDay = 50; // Base rental price per day in dollars
5 const mileageFactor = 0.1; // Additional rate per mile driven
6 const ageFactor = 0.05; // Additional rate per year of vehicle age
7
8 // Calculate additional rate based on mileage and age
9 const mileageRate = city_mpg * mileageFactor;
10 const ageRate = (new Date().getFullYear() - year) * ageFactor;
11
12 // Calculate total rental rate per day
13 const rentalRatePerDay = basePricePerDay + mileageRate + ageRate;
14
15 return rentalRatePerDay.toFixed(0);
16};
17
18export const updateSearchParams = (type: string, value: string) => {
19 // Get the current URL search params

Callers 1

CarCardFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected