Fix problem with array.sort() function