mergeSort and binarySearch algorithms in JavaScript