comparison function for orderBy
mihaifm opened this issue · comments
Mihai Ciuraru commented
orderBy doesn't take a compare function as parameter, similar to C# LINQ orderBy
zhongchengyi commented
The following two methods have the same effect,but how to set zh-cn
like new Intl.Collator('zh-cn').compare('排','序');
?(https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Collator)
zhongchengyi commented
The possible problems:
- whether has
zh-cn
in other countries.(
In your country, what is the result ofnew Intl.Collator('zh-cn').compare('排','序');
?) - how to solve browser compatibility
Mihai Ciuraru commented
I've released a new version to fix this.
You can now write
var a = ['中','文', '排', '序'];
linq.from(a).orderBy(x=>x, (x, y)=>x.localeCompare(y, 'zh-cn')).toArray()
Modern browsers seem to be fine since they include i18n support, I think only node.js may have issues if you're using a version without ICU support (see here). But if you're writing code for modern browsers you should be fine.