0
function sortStrings(stringList) {

    var retval = "";
    var strings = stringList.split(',');
    var sortedStrings = strings.sort((a,b) => {
                 return a < b;
                 });

    sortedStrings.forEach((str) => {
        retval = str + ',';
    } );

    return retval;
}

what mistake am I making

Juhil Somaiya
  • 873
  • 7
  • 20
Lebza
  • 1
  • 3

1 Answers1

0

Your compare function has an error. The logical operator < only returns either true or false while the compare is expected to return an integer. Integers <0 mean that a < b, integers =0 mean a == b and integers >0 mean that a > b.

To accomplish that with strings, you should use localeCompare:

return a.localeCompare(b)
Delphi1024
  • 183
  • 1
  • 4