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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.