Please help

D

Dietmar Meier

I am very new to Javascript, and have some problems with the code for
sorting. My question is in the following web page: [...]

Untested quickhack for IDs matching /\D+-\d+/:

function sortByID(a, b) {
var A = a["ID"].toLowerCase().replace(/\d/g,""),
B = b["ID"].toLowerCase().replace(/\d/g,""),
C = a["ID"].replace(/\D/g,""),
D = b["ID"].replace(/\D/g,"");
if (A < B) return -1;
else if (A > B) return 1;
else if (C - D < 0) return -1;
else if (C - D > 0) return 1;
else return 0;
}

In addition to that, you should test if a function exists that
is named like the value you get from the location's search before
you call it:

var sortCriteria = location.search.substring(1);
if (sortCriteria && typeof window[sortCriteria] == "function")
kidney.sort(window[sortCriteria]);

ciao, dhgm
 
D

Dietmar Meier

The code works perfectly. It is now sorting correctly: [...]

There's still an error in the other function, sortByPinyin().

Replace

var A = a["Pinyin"].toString.toLowerCase();
var B = b["Pinyin"].toString.toLowerCase();

with

var A = a["Pinyin"].toString().toLowerCase();
var B = b["Pinyin"].toString().toLowerCase();

or, since all these values are of type "string" already, simply

var A = a["Pinyin"].toLowerCase();
var B = b["Pinyin"].toLowerCase();

in lines 134 and 135.

ciao, dhgm
 
D

dungping5

Dietmar said:
The code works perfectly. It is now sorting correctly: [...]

There's still an error in the other function, sortByPinyin().

Replace

var A = a["Pinyin"].toString.toLowerCase();
var B = b["Pinyin"].toString.toLowerCase();

with

var A = a["Pinyin"].toString().toLowerCase();
var B = b["Pinyin"].toString().toLowerCase();

or, since all these values are of type "string" already, simply

var A = a["Pinyin"].toLowerCase();
var B = b["Pinyin"].toLowerCase();

in lines 134 and 135.

ciao, dhgm

Errors corrected accordingly. Now it is in:

www.pinyinology.com/sortable/sort2.html

Thanks again for expertise and kindness.

Sincerely,
Juli Zhang
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Help please 8
Please Help 2
How to keep window in place? 1
Hello and Help please :-) 1
Can't solve problems! please Help 0
Please Help? 0
Malicious Coding Help Please 5
Help please 0

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,609
Members
45,253
Latest member
BlytheFant

Latest Threads

Top