Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #34289

Re: Improve my sort!

Newsgroups comp.lang.javascript
Date 2017-11-04 14:16 -0700
References <29745427-ec33-4eea-b8ac-e72ef8b416de@googlegroups.com> <6e1799aa-73cd-4ceb-b6bb-c8e0dd04b378@googlegroups.com> <586dd7cc-dbe7-425b-aadb-8177f244bc93@googlegroups.com> <f34550a2-30d4-4d84-a758-f81ad4dddc01@googlegroups.com> <3e760751-4e27-4aec-9bfe-57139be7f7f9@googlegroups.com>
Message-ID <53264473-7e2f-41b7-bf95-57fcd0f271f2@googlegroups.com> (permalink)
Subject Re: Improve my sort!
From "Michael Haufe (TNO)" <tno@thenewobjective.com>

Show all headers | View raw


jonas.t...@gmail.com wrote:
 
> Sure you can't have problem understand the algorithm

I "have problem understand" the presentation. I don't even want to look at the algorithm in it's current form if it can't pass a basic linter and is presented in a quirks mode html page without formatting.

> function jtindexsort(){ 
> var starttime = new Date().getTime();
> countval= new Array(); 
> //Initiate array range
> for (j=start;j<end;j++){ 
> countval[j]=0; 
> } 
> var temp;
> 
> //Put them on correct index
> for (var i=0;i<numberofvalues;i++){ 
>   temp=dval[i]; 
>   countval[temp]=countval[temp]+1; 
> } 
> p=0;
> 
> 
> 
> offset=0; 
> for (var i=start;i<end;i++){ 
> dval.fill(i,offset,offset+countval[i]); 
> offset=offset+countval[i]; 
> } 
> 
> var endtime = new Date().getTime();
> var timed = endtime - starttime;
> document.sort.functime.value=timed;
> }
> 
> If you think that ones to hard to analyse for your febble mind try the one below, it easy enough to teach a ten year old. Or to be created by a ten year old.

Gladly for my years of formal education in the relevant field I don't have to use my "febble" mind to criticize:

<http://www.typescriptlang.org/play/index.html#src=function jtindexsort() {%0D%0A var starttime %3D new Date().getTime()%3B%0D%0A countval %3D new Array()%3B%0D%0A %2F%2FInitiate array range%0D%0A for (j %3D start%3B j < end%3B j%2B%2B) {%0D%0A countval[j] %3D 0%3B%0D%0A }%0D%0A var temp%3B%0D%0A %2F%2FPut them on correct index%0D%0A for (var i %3D 0%3B i < numberofvalues%3B i%2B%2B) {%0D%0A temp %3D dval[i]%3B%0D%0A countval[temp] %3D countval[temp] %2B 1%3B%0D%0A }%0D%0A p %3D 0%3B%0D%0A offset %3D 0%3B%0D%0A for (var i %3D start%3B i < end%3B i%2B%2B) {%0D%0A dval.fill(i%2C offset%2C offset %2B countval[i])%3B%0D%0A offset %3D offset %2B countval[i]%3B%0D%0A }%0D%0A var endtime %3D new Date().getTime()%3B%0D%0A var timed %3D endtime - starttime%3B%0D%0A document.sort.functime.value %3D timed%3B%0D%0A}>

> So tell me what is it you object to?

Without even looking at the algorithm proper:

1- Free variables
2- mixing of DOM and the sorting algorithm
3- Not using the appropriate measurement API for this (performance.now)
4- combining performance measurement with the algorithm
5- redefining i
6- not using array literal notation

> function jtindexsort(){ 
> //Initiate array range
> q=0; 
> countval.fill(q,start,end); 
> var temp;
> //Put them on correct index
> for (var i=0;i<numberofvalues;i++){ 
>   temp=dval[i]; 
>   countval[temp]=countval[temp]+1; 
> } 
> offset=0; 
> for (var i=start;i<end;i++){ 
> dval.fill(i,offset,offset+countval[i]); 
> offset=offset+countval[i]; 
> } 
> }

Again, no thought required on my part here:

<http://www.typescriptlang.org/play/index.html#src=function jtindexsort() {%0D%0A %2F%2FInitiate array range%0D%0A q %3D 0%3B%0D%0A countval.fill(q%2C start%2C end)%3B%0D%0A var temp%3B%0D%0A %2F%2FPut them on correct index%0D%0A for (var i %3D 0%3B i < numberofvalues%3B i%2B%2B) {%0D%0A temp %3D dval[i]%3B%0D%0A countval[temp] %3D countval[temp] %2B 1%3B%0D%0A }%0D%0A offset %3D 0%3B%0D%0A for (var i %3D start%3B i < end%3B i%2B%2B) {%0D%0A dval.fill(i%2C offset%2C offset %2B countval[i])%3B%0D%0A offset %3D offset %2B countval[i]%3B%0D%0A }%0D%0A}>

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 05:50 -0700
  Re: Improve my sort! "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-11-04 11:54 -0700
    Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 11:57 -0700
      Re: Improve my sort! "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-11-04 12:40 -0700
        Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 13:20 -0700
          Re: Improve my sort! "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-11-04 13:59 -0700
            Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 14:02 -0700
            Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 14:05 -0700
            Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 14:06 -0700
        Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 13:26 -0700
          Re: Improve my sort! "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-11-04 14:16 -0700
            Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 14:23 -0700
              Re: Improve my sort! "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-11-04 14:40 -0700
                Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 14:48 -0700
                Re: Improve my sort! "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-11-04 14:53 -0700
                Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 15:08 -0700
                Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 14:51 -0700
                Re: Improve my sort! "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-11-04 15:11 -0700
            Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 14:27 -0700
              Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 14:29 -0700
    Re: Improve my sort! Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-11-05 20:21 +0100
      Re: Improve my sort! "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-11-05 16:14 -0800
        Re: Improve my sort! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-11-06 00:23 +0000
          Re: Improve my sort! Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-11-06 02:53 +0100
  Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 12:02 -0700
    Re: Improve my sort! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-11-04 20:22 +0000
      Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 13:48 -0700
        Re: Improve my sort! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-11-04 22:08 +0000
          Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 15:14 -0700
            Re: Improve my sort! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-11-04 23:12 +0000
              Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 17:14 -0700
          Re: Improve my sort! "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-11-04 15:16 -0700

csiph-web