Jump to content

Alphabetical Order


The Little Guy

Recommended Posts

What is the best way to compare two strings and alphabetize them?

 

if(string >= string2){
$("#"+currentTestID).before(html);
}

 

But that doesn't seem to always work.

I had these three strings:

- Chrysanthemum.jpg

- Cindy.jpg

- Jaimee.jpg

 

I was then trying to decide where to place this string:

- Family.jpg

 

The code above decided it goes best between the two strings That start with "C", when really it should go after "Cindy.jpg".

 

So, Am I comparing strings wrong for alphabetizing?

Link to comment
https://forums.phpfreaks.com/topic/260142-alphabetical-order/
Share on other sites

string is one of the following (loop through them):

Chrysanthemum.jpg

Cindy.jpg

Jaimee.jpg

 

string2 is:

Family.jpg

 

here is the actual code I am using if that helps:

$("td.basename").each(function(){
var itmid = $(this).parent().attr("id");
var type = $(this).parent().children(".type").text().toLowerCase();
if($(this).text() >= newName && !added && type != "folder"){
	$("#"+itmid).before("<tr class='item' id='item_"+openFile+"'>"+rowData+"</tr>");
	added = true;
	return;
}
});

Link to comment
https://forums.phpfreaks.com/topic/260142-alphabetical-order/#findComment-1333316
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.