Change javascript implementation of merge sort to function instead of array prototype