First of all, it’s nonsensical - by definition this will be undefined since the last index in any array is its length - 1. But did you want to return an element from the array? Is that what you wanted?
With a small tweak to this line, I was able to get your code to pass.
You are absolutely right mate, I forgot to change that line to the index of the last element plus 1 thus changing it to sortedArr.length solved the problem. Thanks!