Created
January 15, 2021 00:30
-
-
Save cameronmoreau/8fb608c6e553245ad1baf908e67dabe9 to your computer and use it in GitHub Desktop.
Used for Gozova WWW
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const HOUSEHOLD = { | |
"650_sqft_apt": 390, | |
"1300_sqft_townhouse": 780, | |
"2000_sqft_house": 1200, | |
}; | |
const ITEMS = { | |
queen_mattress: 30, | |
queen_bed_Frame: 45, | |
"4seat_dining_table": 30, | |
"3cushon_couch": 34, | |
medium_box: 3, | |
desk: 35, | |
"3drawer_dresser": 10, | |
nightstand: 10, | |
}; | |
export function calculatePriceEstimate( | |
miles: number, | |
itemIds: string[] | |
): number { | |
if (itemIds.length == 1 && itemIds[0] in HOUSEHOLD) { | |
return HOUSEHOLD[itemIds[0]]; | |
} | |
const base = itemIds.reduce((acc, item) => { | |
if (!(item in ITEMS)) { | |
throw new Error("Invalid item: " + item); | |
} | |
return ITEMS[item] + acc; | |
}, 0); | |
return Math.round(base + calculateMileage(miles) / 100); | |
} | |
const calculateMileage = (miles: number): number => { | |
let fee = 150; | |
if (miles > 25) fee = 250; | |
else if (miles > 15 && miles <= 25) fee = 200; | |
return miles * fee; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment