Implementing Bubble sort in javascript