15 pts
Create a function that takes an array of integers (arr) and an integer (num) and returns the sum of two values (in the given array), that is the highest possible sum WITHOUT going OVER the given integer (num). Example: bestValuePair([2,4,0,9],7) should return 6 because 4 + 2 is the highest possible pair of values that is not greater than the given number of 7. You can assume there will not be any ties for best value pair and that the given array (arr) will always contain one valid pair.
function bestValuePair(arr,num){
//Enter your code below
}
function bestValuePair(arr,num){
//Enter your code below
}
Test Cases:
-
bestValuePair([2,4,6,8],9) to return 8
-
bestValuePair([0,-1,4,3,7],6) to return 6
-
bestValuePair([-1,2,6],4) to return 1