Created
February 16, 2023 11:32
-
-
Save lubien/126027495b88808caece887172a30d79 to your computer and use it in GitHub Desktop.
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
// @ts-check | |
// | |
// The line above enables type checking for this file. Various IDEs interpret | |
// the @ts-check directive. It will give you helpful autocompletion when | |
// implementing this exercise. | |
/** | |
* Determines whether or not you need a licence to operate a certain kind of vehicle. | |
* | |
* @param {string} kind | |
* @returns {boolean} whether a license is required | |
*/ | |
export function needsLicense(kind) { | |
return ['car', 'truck'].includes(kind) | |
} | |
/** | |
* Helps choosing between two options by recommending the one that | |
* comes first in dictionary order. | |
* | |
* @param {string} option1 | |
* @param {string} option2 | |
* @returns {string} a sentence of advice which option to choose | |
*/ | |
export function chooseVehicle(option1, option2) { | |
const alphabeticalFirst = [option1, option2].sort().shift() | |
return `${alphabeticalFirst} is clearly the better choice.` | |
} | |
/** | |
* Calculates an estimate for the price of a used vehicle in the dealership | |
* based on the original price and the age of the vehicle. | |
* | |
* @param {number} originalPrice | |
* @param {number} age | |
* @returns {number} expected resell price in the dealership | |
*/ | |
export function calculateResellPrice(originalPrice, age) { | |
if (age < 3) { return originalPrice * 0.8 } | |
if (age <= 10) { return originalPrice * 0.7 } | |
return originalPrice * 0.5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment