Forum Discussion

DevaV's avatar
DevaV
Contributor
14 years ago

Discrepancy between Java sorting and Windows file sorting

Hi, 



While automating the verification of sorting using JavaScript we are facing an issue. The Java sort function behavior differs from the Windows sorting behavior.  The files sorted includes filenames with special characters(See attached screenshot Sort_Files.JPG ). While automating this verification using sort() function in JavaScript, the sorting does not happen as Windows sorting(The files with special characters are placed at the last) whereas in Windows sorting  the files with special characters are placed at the top.  Kindly guide us to solve the issue.



We have tried sorting using the below function:



 

function sortAscending(a,b){

    return ((String(a) < String(b)) ? -1 :
((String(a) > String(b)) ? 1 : 0))

}



function test() {

    myArray.sort(sortAscending);

}





Thanks in advance,

Deva V