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


Groups > comp.lang.javascript > #34268 > unrolled thread

Arrray fill vs looping thru.

Started byjonas.thornvall@gmail.com
First post2017-11-04 04:11 -0700
Last post2017-11-04 05:24 -0700
Articles 6 — 2 participants

Back to article view | Back to comp.lang.javascript


Contents

  Arrray fill vs looping thru. jonas.thornvall@gmail.com - 2017-11-04 04:11 -0700
    Re: Arrray fill vs looping thru. jonas.thornvall@gmail.com - 2017-11-04 04:20 -0700
      Re: Arrray fill vs looping thru. jonas.thornvall@gmail.com - 2017-11-04 04:29 -0700
        Re: Arrray fill vs looping thru. JJ <jj4public@vfemail.net> - 2017-11-04 18:53 +0700
    Re: Arrray fill vs looping thru. jonas.thornvall@gmail.com - 2017-11-04 05:06 -0700
      Re: Arrray fill vs looping thru. jonas.thornvall@gmail.com - 2017-11-04 05:24 -0700

#34268 — Arrray fill vs looping thru.

Fromjonas.thornvall@gmail.com
Date2017-11-04 04:11 -0700
SubjectArrray fill vs looping thru.
Message-ID<a9115f4e-8686-427f-8a27-d98f4bebd0cc@googlegroups.com>
Could i use array fill instead of loop thru filling up values but how would i set offset?

offset=0;
for (var i=0;i<numberofvalues){
dval.Array(countval[i]).fill(i);
offset=offset+countval[i];
}

But i do not understand can i set an offset with fill, so as you see i never use it above. 

***HOW DO I MAKE THE FILL AT THE START ENTRY USING OFFSET***?
Is the fill function faster then using loop thru, i save a loop?

[toc] | [next] | [standalone]


#34269

Fromjonas.thornvall@gmail.com
Date2017-11-04 04:20 -0700
Message-ID<ce1b6e3f-7a0f-4f8d-ada3-87cb48875eb0@googlegroups.com>
In reply to#34268
Den lördag 4 november 2017 kl. 12:11:37 UTC+1 skrev jonas.t...@gmail.com:
> Could i use array fill instead of loop thru filling up values but how would i set offset?
> 
> offset=0;
> for (var i=0;i<numberofvalues){
> dval.Array(countval[i]).fill(i);
> offset=offset+countval[i];
> }
> 
> But i do not understand can i set an offset with fill, so as you see i never use it above. 
> 
> ***HOW DO I MAKE THE FILL AT THE START ENTRY USING OFFSET***?
> Is the fill function faster then using loop thru, i save a loop?

This is the original code i try to replace, the index of countval represent "a stored value" then actual element at each index "is number of occurences of stored value", can i remove the innerloop below using fill?
And will it be faster?

I would be glad on some help howto use fill with an offset. 
I do understand that Array(3).fill(4) will fill element 1-3 in whatever array with 4,4,4 but that is index 0,1,2? how can i set an offset "startpoint".

JT



for (var j=start;j<end;j++){ 
temp=countval[j] 
for (var k=0;k<temp;k++){ 
dval[p]=j; 
p++;
} 
}

[toc] | [prev] | [next] | [standalone]


#34270

Fromjonas.thornvall@gmail.com
Date2017-11-04 04:29 -0700
Message-ID<85f556d9-8716-4d45-878e-f37a5c1aded2@googlegroups.com>
In reply to#34269
Den lördag 4 november 2017 kl. 12:20:47 UTC+1 skrev jonas.t...@gmail.com:
> Den lördag 4 november 2017 kl. 12:11:37 UTC+1 skrev jonas.t...@gmail.com:
> > Could i use array fill instead of loop thru filling up values but how would i set offset?
> > 
> > offset=0;
> > for (var i=0;i<numberofvalues){
> > dval.Array(countval[i]).fill(i);
> > offset=offset+countval[i];
> > }
> > 
> > But i do not understand can i set an offset with fill, so as you see i never use it above. 
> > 
> > ***HOW DO I MAKE THE FILL AT THE START ENTRY USING OFFSET***?
> > Is the fill function faster then using loop thru, i save a loop?
> 
> This is the original code i try to replace, the index of countval represent "a stored value" then actual element at each index "is number of occurences of stored value", can i remove the innerloop below using fill?
> And will it be faster?
> 
> I would be glad on some help howto use fill with an offset. 
> I do understand that Array(3).fill(4) will fill element 1-3 in whatever array with 4,4,4 but that is index 0,1,2? how can i set an offset "startpoint".
> 
> JT
> 
> 
> 
> for (var j=start;j<end;j++){ 
> temp=countval[j] 
> for (var k=0;k<temp;k++){ 
> dval[p]=j; 
> p++;
> } 
> }

But how does fill work with statement like Array(0).fill(4) will it still make the function call that would be a waste so i hope not?

[toc] | [prev] | [next] | [standalone]


#34271

FromJJ <jj4public@vfemail.net>
Date2017-11-04 18:53 +0700
Message-ID<1pe7yavhi27e.xjw4a5m2wl9x$.dlg@40tude.net>
In reply to#34270
On Sat, 4 Nov 2017 04:29:44 -0700 (PDT), jonas.thornvall@gmail.com wrote:

> Den lördag 4 november 2017 kl. 12:20:47 UTC+1 skrev jonas.t...@gmail.com:
>> Den lördag 4 november 2017 kl. 12:11:37 UTC+1 skrev jonas.t...@gmail..com:
>>> Could i use array fill instead of loop thru filling up values but how would i set offset?
>>> 
>>> offset=0;
>>> for (var i=0;i<numberofvalues){
>>> dval.Array(countval[i]).fill(i);
>>> offset=offset+countval[i];
>>> }
>>> 
>>> But i do not understand can i set an offset with fill, so as you see i never use it above. 
>>> 
>>> ***HOW DO I MAKE THE FILL AT THE START ENTRY USING OFFSET***?
>>> Is the fill function faster then using loop thru, i save a loop?
>> 
>> This is the original code i try to replace, the index of countval represent "a stored value" then actual element at each index "is number of occurences of stored value", can i remove the innerloop below using fill?
>> And will it be faster?
>> 
>> I would be glad on some help howto use fill with an offset. 
>> I do understand that Array(3).fill(4) will fill element 1-3 in whatever array with 4,4,4 but that is index 0,1,2? how can i set an offset "startpoint".
>> 
>> JT
>> 
>> for (var j=start;j<end;j++){ 
>> temp=countval[j] 
>> for (var k=0;k<temp;k++){ 
>> dval[p]=j; 
>> p++;
>> } 
>> }
> 
> But how does fill work with statement like Array(0).fill(4) will it still make the function call that would be a waste so i hope not?

Check the MDN reference for the `fill()` method.

<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill>

You should bookmark that site too, since it's a pretty good reference for
most web specifications.

[toc] | [prev] | [next] | [standalone]


#34272

Fromjonas.thornvall@gmail.com
Date2017-11-04 05:06 -0700
Message-ID<42ecdf08-33e9-4575-a719-a2d73cb4ac21@googlegroups.com>
In reply to#34268
Den lördag 4 november 2017 kl. 12:11:37 UTC+1 skrev jonas.t...@gmail.com:
> Could i use array fill instead of loop thru filling up values but how would i set offset?
> 
> offset=0;
> for (var i=0;i<numberofvalues){
> dval.Array(countval[i]).fill(i);
> offset=offset+countval[i];
> }
> 
> But i do not understand can i set an offset with fill, so as you see i never use it above. 
> 
> ***HOW DO I MAKE THE FILL AT THE START ENTRY USING OFFSET***?
> Is the fill function faster then using loop thru, i save a loop?

I think i get it

Example fruits.fill("Kiwi", 2, 4)

offset=0;
for (var i=0;i<numberofvalues){
dval.Array(countval[i]).fill(i,offset,offset+countval[i]);
offset=offset+countval[i];
}

Does it seem reasonable?

[toc] | [prev] | [next] | [standalone]


#34273

Fromjonas.thornvall@gmail.com
Date2017-11-04 05:24 -0700
Message-ID<c836a5b1-7c18-44bf-8286-5e35b6ca5480@googlegroups.com>
In reply to#34272
Den lördag 4 november 2017 kl. 13:07:08 UTC+1 skrev jonas.t...@gmail.com:
> Den lördag 4 november 2017 kl. 12:11:37 UTC+1 skrev jonas.t...@gmail.com:
> > Could i use array fill instead of loop thru filling up values but how would i set offset?
> > 
> > offset=0;
> > for (var i=0;i<numberofvalues){
> > dval.Array(countval[i]).fill(i);
> > offset=offset+countval[i];
> > }
> > 
> > But i do not understand can i set an offset with fill, so as you see i never use it above. 
> > 
> > ***HOW DO I MAKE THE FILL AT THE START ENTRY USING OFFSET***?
> > Is the fill function faster then using loop thru, i save a loop?
> 
> I think i get it
> 
> Example fruits.fill("Kiwi", 2, 4)
> 
> offset=0;
> for (var i=0;i<numberofvalues){
> dval.Array(countval[i]).fill(i,offset,offset+countval[i]);
> offset=offset+countval[i];
> }
> 
> Does it seem reasonable?
Well this look better "correct"

offset=0; 
for (var i=0;i<numberofvalues;i++){ 
dval.fill(i,offset,offset+countval[i]); 
offset=offset+countval[i]; 
}
I think i got it to work, but the timing seem to be the same, but this is very few occurences on every entry 0-3, if the sample data more dense it could give positive effects?

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web