jennschiffer / jortsort

the official website for jortSorting
http://jort.technology
MIT License
111 stars 5 forks source link

May I ask a question? #2

Closed eribeiro closed 10 years ago

eribeiro commented 10 years ago

Hi,

I am not a good JS coder (or any other kind of coder, probably). Therefore, excuse me if what I am suggesting is utterly stupid, but jortSort implementation couldn't be as below?

   var jortSort = function( array ) {
       for (var i = 0; i < array.length - 1; i++) {
            if (array[i] > array[i+1]) {
               return false;
            }
       }
       return true;
  }

No need to sort the array in the first place, but I can be slipping some important detail. :)

jennschiffer commented 10 years ago

you get a nasty JORT_ERROR: i is less than 0 error when the array is empty or has 1 item woops too bad :santa:

eribeiro commented 10 years ago

Cool. Are you running a automatic test suite that output this message?

Because if array.length = 0 or array.length = 1 the for-loop is never executed (returning the array as "sorted"). I fail to see where i variable could be less than zero in the snippet above. :jack_o_lantern: