0

I am writing an Google Scripts attached to Google Form and Google Sheet. I have a list of names where some have entered the data with lower case and upper case. I am trying to sort - however, the standard .sort() is sorting the Upper Case first and then the lower case - which is very confusing.

Could you suggest how i can sort a data so that it doesn't take into account the case for sorting - but retains the original uppwer and lower cases.

For e.g. var a = {Charlie, alpha, delta, Bravo};

Desired output {alpha, Bravo, Charlie, delta}.

Thank you.

Regards, ray

1 Answers1

2

You can define a custom function in javascript sort. eg:

var a = ["Charlie", "alpha", "delta", "Bravo"];
a = a.sort(function(x, y){
      x = x.toLowerCase()
      y = y.toLowerCase()
      if (x < y) {
        return -1;
      }
      if (x > y) {
        return 1;
      }
       return 0;
    })
// Outputs [ "alpha", "Bravo", "Charlie", "delta" ]
Anees Hameed
  • 5,916
  • 1
  • 39
  • 43