From Array.prototype.sort()
documentation:
The default sort order is built upon converting the elements into
strings, then comparing their sequences of UTF-16 code units values.
What if target array's elements are objects and we want apply above algorithm to targetKey
's value?
const targetArray = [
{ targetKey: 'March' },
{ targetKey: 'Jan' },
{ targetKey: 'Feb' },
{ targetKey: 'Dec' }
]
Expected result:
[
{ targetKey: 'Dec' },
{ targetKey: 'Feb' },
{ targetKey: 'Jan' },
{ targetKey: 'March' }
]
Some simple solutions?
Warning: We don't considering the ordering by alphabet in this question. We need to order due sequences of UTF-16 code units values.
No comments:
Post a Comment