My bad! Miss read it. ^That still sorts in ascending order only.
On Fri, Jun 6, 2014 at 5:08 PM, Hemanth H.M <hemanth...@gmail.com> wrote: > Something like: > > ```js > Number.compare = (n1, n2) -> (n1 - n2) / Math.abs(n1 - n2) || 0; > ``` > > > > On Fri, Jun 6, 2014 at 12:40 PM, Mathias Bynens <mathi...@opera.com> > wrote: > >> On 6 Jun 2014, at 01:15, Axel Rauschmayer <a...@rauschma.de> wrote: >> >> > 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) >> > ``` >> >> That sorts in ascending order. What if you need to sort in descending >> order? Would there need to be a built-in function for that too? >> _______________________________________________ >> es-discuss mailing list >> es-discuss@mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> > > > > -- > *'I am what I am because of who we all are'* > h3manth.com <http://www.h3manth.com> > *-- Hemanth HM * > -- *'I am what I am because of who we all are'* h3manth.com <http://www.h3manth.com> *-- Hemanth HM *
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss