findClosestToEnd(compareFct) { //ALGORITHM HERE }
findClosestToEnd(compareFct) {
firstIndex = get index of first (left) end of array
lastIndex = get index of last (right) end of array
firstMatchingIndex = search for first matching elem (index)
lastMatchingIndex = search for last matching elem (index)
leftDistance = distance from firstIndex to the firstMatchingIndex
rightDistance = distance from lastMatchingIndex to the lastIndex
}
findClosestToEnd(compareFct) { firstIndex = 0 lastIndex = this.length - 1 firstMatchingIndex = search for first matching elem (index) lastMatchingIndex = search for last matching elem (index) leftDistance = firstMatchingIndex - firstIndex rightDistance = lastIndex - lastMatchingIndex }
firstMatchingIndex = search for first matching element (index) using compareFct lastMatchingIndex = search for last matching element (index) using compareFct