# why does this merge sort code work in python but not in javascript

Does anyone know why this code isn’t working, I tried the same code in python and it worked perfectly.

``````function merge(l,m,r) {
let divider = m+1
let l_cache = l
let  out_list = []
for (let i = 0; i < r-l+1; i++){
if (l > m){
out_list.push(numbers[divider])
divider += 1
}else if(divider > r){
out_list.push(numbers[l])
l += 1
}else if(numbers[l] < numbers[divider]){
out_list.push(numbers[l])
l += 1
}else if(numbers[l] >= numbers[divider]){
out_list.push(numbers[divider])
divider += 1
}
}
for (let i = 0; i < out_list.length; i++){
numbers[i+l_cache] = out_list[i]
}
}
function MergeSort(l,r) {
if (l < r){
let m = Math.floor((l+r-1)/2)
MergeSort(l,m)
MergeSort(m+1,r)
merge(l,m,r)
}
}
var numbers = [42, 60, 33, 79, 15, 0, 88, 62, 27, 46]
MergeSort(0,numbers.length-1)
``````

input = [42, 60, 33, 79, 15, 0, 88, 62, 27, 46]

output = [0, 15, 27, 33, 42, 46, 60, 46, 62 ,62]

expected output = [0, 15, 27, 33, 42, 46, 60, 62, 79, 88]

### 133 thoughts on “why does this merge sort code work in python but not in javascript”

1. Hmm is anyone else having problems with the images on this
blog loading? I’m trying to determine if its a problem on my end or
if it’s the blog. Any feed-back would be greatly appreciated. http://antiibioticsland.com/Ampicillin.htm

2. It’s an remarkable paragraph designed for all the online users; they will get benefit from it
I am sure. http://droga5.net/

3. Oh my goodness! Amazing article dude! Thank you
I don’t know the reason why I can’t join it. Is there anyone else having similar RSS problems?
Anybody who knows the solution can you kindly respond? Thanx!! http://herreramedical.org/ivermectin