Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #35477
| Newsgroups | comp.lang.javascript |
|---|---|
| Subject | Re: Not understanding "sort" with an argument |
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
| References | <c3146bef-749a-4881-bd24-62e6a9b8df28@googlegroups.com> <d7kqmdpit250iuia6osb956lgva662k3dn@4ax.com> <7fee9579-fe62-4b1d-ac30-61ca33fe32c9@googlegroups.com> <kt96ndddfmkbn0jcv5anhqgb6vlrn4nai5@4ax.com> |
| Date | 2018-08-14 23:00 +0200 |
| Message-ID | <XnsA93EE9FA650D8eejj99@194.109.6.166> (permalink) |
John G Harris <niam@jghnorth.org.uk.invalid> wrote on 14 Aug 2018 in comp.lang.javascript: > On Tue, 14 Aug 2018 11:25:53 -0700 (PDT), bit-naughty@hotmail.com > wrote: > >>On Friday, August 10, 2018 at 2:17:08 PM UTC+5:30, John G Harris wrote: >>> >>> The function comparePerson has been given to friends.sort, which uses >>> it to help it do the sorting. >> >>"help" it *how*? > > Well, when you want to sort things into order you have to be able to > tell whether this thing is before or after that thing. That's what the > comparePerson function does. The sort function does many of these > comparisons in order to do its job of making earlier things come > before later things. Not so. In an array, and this is about sorting an array [or a string posing as an array of letters] there is no "earlier" and "later", just difference in element position number. > That's the help the compare function gives to the sort function. No. The compare function is not just a helper, it defines the algoritm that acts as the "worker" of the sort, determining in every internal sorting-step if two adjacent elements need to be toggled or not. The sort therefore listens to which of the three values the compare returns, *1, 0 or +1 for less than, equal end more than. Such a sort might be alphabetical, numerical, or much more compound. > You might like to read up on sort algorithms, but beware, the more > efficient the algorithm the more compicated the code :-( Nonsense, methinks. What gives you that idea? -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Not understanding "sort" with an argument bit-naughty@hotmail.com - 2018-08-10 01:11 -0700
Re: Not understanding "sort" with an argument John G Harris <niam@jghnorth.org.uk.invalid> - 2018-08-10 09:47 +0100
Re: Not understanding "sort" with an argument bit-naughty@hotmail.com - 2018-08-14 11:25 -0700
Re: Not understanding "sort" with an argument John G Harris <niam@jghnorth.org.uk.invalid> - 2018-08-14 20:04 +0100
Re: Not understanding "sort" with an argument "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2018-08-14 23:00 +0200
Re: Not understanding "sort" with an argument "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2018-08-14 23:02 +0200
Re: Not understanding "sort" with an argument Julio Di Egidio <julio@diegidio.name> - 2018-08-15 04:20 -0700
Re: Not understanding "sort" with an argument John G Harris <niam@jghnorth.org.uk.invalid> - 2018-08-15 19:15 +0100
Re: Not understanding "sort" with an argument "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2018-08-15 21:56 +0200
Re: Not understanding "sort" with an argument John G Harris <niam@jghnorth.org.uk.invalid> - 2018-08-16 15:24 +0100
Re: Not understanding "sort" with an argument Julio Di Egidio <julio@diegidio.name> - 2018-08-16 07:51 -0700
Re: Not understanding "sort" with an argument John G Harris <niam@jghnorth.org.uk.invalid> - 2018-08-16 18:51 +0100
Re: Not understanding "sort" with an argument Julio Di Egidio <julio@diegidio.name> - 2018-08-16 11:21 -0700
Re: Not understanding "sort" with an argument John G Harris <niam@jghnorth.org.uk.invalid> - 2018-08-17 10:44 +0100
Re: Not understanding "sort" with an argument Julio Di Egidio <julio@diegidio.name> - 2018-08-15 03:58 -0700
csiph-web