Idea for ECMAScript 7: Number.compare(a, b)
Axel Rauschmayer
axel at rauschma.de
Thu Jun 5 16:15:26 PDT 2014
It’d be nice to have a built-in way for comparing numbers, e.g. when sorting arrays.
```js
// Compact ECMAScript 6 solution
// Risk: number overflow
[1, 5, 3, 12, 2].sort((a,b) => a-b)
// Proposed new function:
[1, 5, 3, 12, 2].sort(Number.compare)
```
--
Dr. Axel Rauschmayer
axel at rauschma.de
rauschma.de
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140606/771ec3da/attachment.html>
More information about the es-discuss
mailing list