14 pts
Create a function where a given integer (x) and an array (arr) returns the number at index (x) if the array was sorted in ascending order.
Ex: getX(2, [5,10,-3,7,9]) will return 5 because when sorted, 5 is the 2nd number from the array You can assume the given array (arr) will always contain enough values to return a value at the given index
function getX(x, arr){
//Enter your code here
}
function getX(x, arr){
//Enter your code here
}
Test Cases:
-
getX(2, [5, 1, 4, 2, 3]) to return 3
-
getX(1, [10, 1, -1]) to return 1
-
getX(3, [7, 6, 8, 5]) to return 8