Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

|desc|C} isn't properly pushing lowercase down on the doc site book example. #13

Closed
jsdevel opened this issue Jan 19, 2013 · 3 comments
Closed
Labels

Comments

@jsdevel
Copy link
Owner

jsdevel commented Jan 19, 2013

No description provided.

@jsdevel
Copy link
Owner Author

jsdevel commented Jan 23, 2013

So, I've pretty much determined that depending on Array.prototype.sort for consistent results is a lost cause. Implementations aren't required to deliver consistent results, which sucks! No biggie, This should do just fine. Initial testing showed that the worst case never went over O^2. Here's the algorithm.

a=[3,4,3,2,6,2,4,6,2,3,4,5,3,2,43,7,87,3,423,344,4,3,2346,1,4,4,45624576245,7,23457,245,72,45,72,457,2,457,245,72,457,245,7,2457,2,1];
compare=function(a,b){
   if(a>b)return 1;
};
function sort(array, compare){
   var len = array.length;
   var max = len*len;
   var count=0;
   var i=1;
   var successfulIndex=i-1;
   var regressed=false;
   for(;i<len;i++){
      if(count===max)break;
      count++;
      if(compare(array[i-1],array[i])===1){
         array.splice(i,0,array.splice(i-1, 1)[0]);
         i-=2;
         if(i<0)i=0;
         regressed=true;
      } else if(regressed){
            regressed=false;
            i=successfulIndex;
      } else {
         successfulIndex++;
      }
   }
}
b=Date.now();sort(a,compare);console.log(Date.now()-b);

@jsdevel
Copy link
Owner Author

jsdevel commented Jan 23, 2013

This will work with a random sort as well.

@jsdevel
Copy link
Owner Author

jsdevel commented Jan 24, 2013

Part of the issue is that toLowerCase is being applied on the entire string in GetSortArray.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant