mihaifm / linq

linq.js - LINQ for JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

comparison function for orderBy

mihaifm opened this issue · comments

orderBy doesn't take a compare function as parameter, similar to C# LINQ orderBy

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)
image
image

The possible problems:

  1. whether has zh-cn in other countries.(
    In your country, what is the result of new Intl.Collator('zh-cn').compare('排','序'); ?)
  2. how to solve browser compatibility

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.