Mergesort implementation in JavaScript