MergeSort in Javascript I implemented the following mergesort algorithm in JavaScript, but I want to know your opinion about if is possible to do better than this.

function mergesort(list){
    if(list.length &lt; 2){
        return list
    }else if(list.length &gt; 1){
        let n = list.length
        let middle = n/2
        return merge(mergesort(list.slice(0, middle)), mergesort(list.slice(middle, n)))
    }
}

function merge(listA, listB){
    let list = []

    listA.push(Infinity)
    listB.push(Infinity)

    let i = 0
    let j = 0

    while(i &lt; listA.length-1 || j &lt; listB.length-1){
        if(listA[i] &lt; listB[j]){
            list.push(listA[i])
            i++
        }else{
            list.push(listB[j])
            j++
        }
    }

    return list

}


Do you have any idea of how can I improve this?
I don't see a way to improve the algorithm, but here are some general coding tips:

A number can either be greater than 1, or less than 2. So you can use 'else' here instead.

if(list.length &lt; 2){
    return list
}else if(list.length &gt; 1){


Sometimes people create extra variables to improve readability, but here 'n' is less readable than list.length.

let n = list.length


A little bit of commenting can go a long way, for example if you could explain why you add 'Infinity' to the lists in a comment:

listA.push(Infinity)
listB.push(Infinity)