473,390 Members | 1,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

sort which is default compare function

in the default sort which is the compare function used?
alphabetical ordination is so:arry.sort();
but which is the default function used?

is there a good link wich example for alphabetical order
and also for multiarray order? (previous post)


which it is the difference between:
function compareNumbers(a, b)
{return a - b;}
and this:
function compare(a, b)
{ if (a < b by) return -1;
else if (a than b ) return 1;
else return 0;
}
May 26 '07 #1
3 5382
artev wrote on 26 mei 2007 in comp.lang.javascript:
which it is the difference between:
function compareNumbers(a, b)
{return a - b;}
and this:
function compare(a, b)
{ if (a < b by) return -1;
if (a < b)
else if (a than b ) return 1;
else if (a b )
else return 0;
}
No difference when used in a numeric .sort(),
as .sort() only looks for positive, zero or negative.

The first sort function should be faster,
especially important with a large array.

The second one also works in a string compare sort.

In the second function the else-es are not neccessary:

function compare(a, b) {
if (a<b) return -1;
if (a>b) return 1;
return 0;
};
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
May 26 '07 #2
in my previous I have now post a new code that not work
good;
you know where is the problem?
May 26 '07 #3
artev wrote on 26 mei 2007 in comp.lang.javascript:
in my previous I have now post a new code that not work
good;
you know where is the problem?
What and to whom are you talking [about]?

[please always quote on usenet]

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
May 26 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Uwe Mayer | last post by:
Hi, Using PyQt I got a QListView with about 800 entries now (but its intended to be scalable up to about 3000). The first column contains numerical data. Now Qt does the sorting all by its self...
4
by: its me | last post by:
Let's say I have a class of people... Public Class People Public Sex as String Public Age as int Public Name as string end class And I declare an array of this class...
7
by: Christopher Jeris | last post by:
I am relatively new to JavaScript, though not to programming, and I'm having trouble finding the idiomatic JS solution to the following problem. I have a table with (say) fields f1, f2, f3. I...
10
by: Paul Schneider | last post by:
I want to sort a class derived from std::vector with STL sort.: template<typename T, typename fitParaType, typename fitResType> class Manipulator{ // shouldn't I now be able to access private...
18
by: Doug Bell | last post by:
Hi, I have a function that loads Rows from a field in a DataTable into an ArrayList. See below: It also adds a Row (eg "All Areas"). I wanted this new row to be the first record so I added a...
10
by: eiji | last post by:
Hi folks, I have a problem compiling this under VC6! Maybe someone has some minutes to look at this: template<class T> class Compare { public: Compare(){}; virtual ~Compare(){};
4
by: Gaijinco | last post by:
I'm not quite sure why this code doesn't works: #include <iostream> #include <algorithm> #include <vector> #include <string> using namespace std; class word {
14
by: william.hooper | last post by:
There is a longer article about this subject here: http://www.codeproject.com/useritems/SortedList_Bug.asp See the main article and the reply thread started by Robert Rohde. Alternatively look...
3
by: raylopez99 | last post by:
This is an example of using multiple comparison criteria for IComparer/ Compare/CompareTo for List<and Array. Adapted from David Hayden's tutorial found on the net, but he used ArrayList so the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.