Problem
- You know that on average, your car runs on about 25 miles per gallon.
- Considering these factors, write a function that tells you if it is possible to get to the pump or not.
- 이러한 요소를 고려해서, 펌프에 도달할 수 있는지 확인한다.
Solution 01
function zeroFuel(distanceToPump, milesPerGallon, fuelLeft) {
if (milesPerGallon * fuelLeft >= distanceToPump) {
return true;
} else {
return false;
}
}
zeroFuel(50, 25, 2); // true
zeroFuel(50, 25, 1); // false
Solution 02
function zeroFuel(distanceToPump, milesPerGallon) {
return fuelLeft >= distanceToPump / milesPerGallon;
}
zeroFuel(50, 25, 2); // true
zeroFuel(50, 25, 1); // false