Last active
September 7, 2018 02:26
-
-
Save lastday154/9ee6e4c80004ff68681822fe84b933ef to your computer and use it in GitHub Desktop.
optimalUtilization
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
function optimalUtilization(maximumOperatingTravelDistance, | |
forwardShippingRouteList, returnShippingRouteList) | |
{ | |
// WRITE YOUR CODE HERE | |
let currentMax = 0; | |
const result = []; | |
forwardShippingRouteList.forEach((forwardDistance) => { | |
returnShippingRouteList.forEach((returnDistance) => { | |
let distance = forwardDistance[1] + returnDistance[1]; | |
if (currentMax <= distance && distance <= maximumOperatingTravelDistance) { | |
if (result.length > 0 && currentMax < distance) { | |
result = []; | |
} | |
currentMax = distance; | |
result.push([forwardDistance[0], returnDistance[0]]); | |
} | |
}); | |
}); | |
return result; | |
} | |
console.log(optimalUtilization(20, [[1,8], [2,15], [3,9]], [[1,8], [2,11], [3,12]])); |
sudheesh001
commented
Sep 7, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment