How would I go about sorting the k.each by the comment_id(q in the function variable)? This is part of the core-min.js from Social Engine.
k.each(function(o,q){var r=new Element("div",{id:"comment_"+q});var s="<div style='margin-top: 10px; margin-bottom: 20px;'>";if(o.comment_authoruser_id&&o.comment_authoruser_exists){s+="<div style='float: left; text-align: center; width: 90px;'><a href='"+o.comment_authoruser_url+"'><img src='"+o.comment_authoruser_photo+"' class='photo' width='"+o.comment_authoruser_photo_width+"' border='0'></a></div>"}else{s+="<div style='float: left; text-align: center; width: 90px;'><img src='./images/nophoto.png' class='photo' width='75' border='0'></div>"}s+="<div style='overflow: hidden;'>";if(!o.comment_authoruser_id){s+="<div class='profile_comment_author'><b>"+l.Base.Language.Translate(835)+"</b></div>"}else{if(!o.comment_authoruser_exists){s+="<div class='profile_comment_author'><b>"+l.Base.Language.Translate(1071)+"</b></div>"}else{s+="<div class='profile_comment_author'><a href='"+o.comment_authoruser_url+"'><b>"+o.comment_authoruser_displayname+"</b></a></div>"}}s+="<div class='profile_comment_date'>"+o.comment_date+"</div>";r.setProperty("html",o.comment_body);s+="<div class='profile_comment_body' id='profile_comment_body_"+q+"'>"+o.comment_body+" </div>";s+="<div class='profile_comment_links'>";var p=new Array();if(l.Base.Viewer.user_exists&&o.comment_authoruser_id&&o.comment_authoruser_exists){if(l.options.commentLinks.reply&&l.Base.Viewer.user_info.user_id==l.Base.Owner.user_info.user_id&&l.Base.Viewer.user_info.user_id!=o.comment_authoruser_id){p.push("<a href='profile.php?user="+o.comment_authoruser_username+"&v=comments'>"+l.Base.Language.Translate(787)+"</a>")}if(l.options.commentLinks.walltowall&&o.comment_authoruser_id!=l.Base.Owner.user_info.user_id&&o.comment_authoruser_private==false){p.push("<a href=\"javascript:TB_show('"+l.Base.Language.Translate(1032)+"', 'profile_comments.php?user="+l.Base.Owner.user_info.user_username+"&user2="+o.comment_authoruser_username+"&TB_iframe=true&height=450&width=550', '', './images/trans.gif');\">"+l.Base.Language.Translate(891)+"</a>")}if(o.comment_authoruser_id!=l.Base.Viewer.user_info.user_id){p.push("<a href=\"javascript:TB_show('"+l.Base.Language.Translate(784)+"', 'user_messages_new.php?to_user="+o.comment_authoruser_displayname+"&to_id="+o.comment_authoruser_username+"&TB_iframe=true&height=400&width=450', '', './images/trans.gif');\">"+l.Base.Language.Translate(834)+"</a>")}if(o.comment_authoruser_id==l.Base.Viewer.user_info.user_id){p.push('<a class="commentEditLink" href="javascript:void(0);" id=\'comment_edit_link_'+q+"'>"+l.Base.Language.Translate(187)+"</a>")}}if((o.comment_authoruser_exists&&o.comment_authoruser_id==l.Base.Viewer.user_info.user_id)||(l.Base.Viewer.user_exists&&l.Base.Viewer.user_info.user_id==l.Base.Owner.user_info.user_id)){p.push('<a class="commentDeleteLink" href="javascript:void(0);" id=\'comment_delete_link_'+q+"'>"+l.Base.Language.Translate(155)+"</a>")}s+=p.join(" - ");s+=" </div></div></div>";r.setProperty("html",s);r.inject(g);if(r.getElement(".commentEditLink")){r.getElement(".commentEditLink").addEvent("click",function(){l.editComment(q)})}if(r.getElement(".commentDeleteLink")){r.getElement(".commentDeleteLink").addEvent("click",function(){l.confirmDelete(q)})}}