Reputation: 717
Anybody know what options are available?
Chrome console allows the standard options:
'ä'.localeCompare('z', 'de'); // -1
'ä'.localeCompare('z', 'sv'); // 1
Google Apps Script appears to ignore:
'ä'.localeCompare('z', 'de'); // -1
'ä'.localeCompare('z', 'sv'); // -1
Other options are similarly unavailable:
// in German, ä has a as the base letter
'ä'.localeCompare('a', 'de', { sensitivity: 'base' });
// -> 0 in chrome,
// -> 1 in GAS
// in Swedish, ä and a are separate base letters
'ä'.localeCompare('a', 'sv', { sensitivity: 'base' });
// -> 1 in chrome
// -> 1 in GAS
Does it have anything to do with active user's locale? Or does GAS just have a stripped-down version of localeCompare? Or am I doing it wrong?
Upvotes: 1
Views: 859
Reputation:
does GAS just have a stripped-down version of localeCompare
Yes, it does. It runs on Rhino (a JS implementation in Java), in which localeCompare
ignores all arguments after the first one. For example,
"a".localeCompare("b", "c", "d")
is obviously invalid in ECMAScript but runs in GAS, with the arguments "c" and "d" being silently ignored.
This is somewhat similar to the situation with toLocaleString
which acts as toString.
Upvotes: 2