function merge(arr1, arr2) {
var res = []
while(arr1.length && arr2.length) {
if(arr1[0] < arr2[0]) {
res.push(arr1.shift())
} else {
res.push(arr2.shift())
}
}
return res.concat(arr1, arr2)
}
function mergeSort(arr) {
if(arr.length === 1)
return arr
var mid = Math.floor(arr.length / 2),
left = arr.slice(0, mid),
right = arr.slice(mid)
return merge(mergeSort(left), mergeSort(right))
}