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}>