You are viewing a single comment's thread. Return to all comments →
JavaScript
function truckTour(petrolpumps) { // Write your code here // 1km === 1L petrol let startpump; let petrol = 0; petrolpumps.forEach((pp, i) => { if (pp[0] >= pp[1] && !startpump) { startpump = i; petrol = pp[0] - pp[1]; } else if (startpump) { petrol += pp[0] - pp[1]; if(petrol < 0){ startpump = null; } } }); return startpump; }
Seems like cookies are disabled on this browser, please enable them to open this website
Truck Tour
You are viewing a single comment's thread. Return to all comments →
JavaScript