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


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

Option list selection

Started byJonas Thörnvall <jonas.thornvall@gmail.com>
First post2021-11-01 02:23 -0700
Last post2021-11-03 16:15 -0700
Articles 10 — 4 participants

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


Contents

  Option list selection Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-11-01 02:23 -0700
    Re: Option list selection Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-11-01 02:28 -0700
    Re: Option list selection luserdroog <luser.droog@gmail.com> - 2021-11-01 09:17 -0700
      Re: Option list selection Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-11-01 15:05 -0700
      Re: Option list selection Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-11-01 15:10 -0700
        Re: Option list selection luserdroog <luser.droog@gmail.com> - 2021-11-01 19:24 -0700
          Re: Option list selection Julio Di Egidio <julio@diegidio.name> - 2021-11-01 23:54 -0700
            Re: Option list selection luserdroog <luser.droog@gmail.com> - 2021-11-02 05:21 -0700
              Re: Option list selection Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-11-02 12:41 +0000
                Re: Option list selection luserdroog <luser.droog@gmail.com> - 2021-11-03 16:15 -0700

#40507 — Option list selection

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2021-11-01 02:23 -0700
SubjectOption list selection
Message-ID<496b70db-3aaf-41ad-9044-e703be59a92dn@googlegroups.com>
I am pretty sure this code did run a week ago, have their been changes to the API it seem it never enter loop because e.options.length undefined?

function getPortIndex(){
	var e = parent.document.getElementById("out_portsel");
	alert(parent.out_portsel.length);
	for (var i=0;i<parent.out_portsel.length;i++){
		alert("WTF");
			if (e.options[i].value=="FW1884 Control"){ctrlportindex=i; alert(ctrlportindex); break;}
					else{alert("nonevalid port");}
	}
}

[toc] | [next] | [standalone]


#40508

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2021-11-01 02:28 -0700
Message-ID<784cc4a7-f6f4-4707-9781-f12677414cc9n@googlegroups.com>
In reply to#40507
måndag 1 november 2021 kl. 10:23:57 UTC+1 skrev Jonas Thörnvall:
> I am pretty sure this code did run a week ago, have their been changes to the API it seem it never enter loop because e.options.length undefined? 
> 
> function getPortIndex(){ 
> var e = parent.document.getElementById("out_portsel"); 
> alert(parent.out_portsel.length); 
> for (var i=0;i<parent.out_portsel.length;i++){ 
> alert("WTF"); 
> if (e.options[i].value=="FW1884 Control"){ctrlportindex=i; alert(ctrlportindex); break;} 
> else{alert("nonevalid port");} 
> } 
> }
Changed to e.length now it work, but i am pretty sure i used length of the form last week.

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


#40509

Fromluserdroog <luser.droog@gmail.com>
Date2021-11-01 09:17 -0700
Message-ID<4552c8e0-d9da-4b3a-95f8-fe5f4a721b07n@googlegroups.com>
In reply to#40507
On Monday, November 1, 2021 at 4:23:57 AM UTC-5, jonas.t...@gmail.com wrote:
> I am pretty sure this code did run a week ago, have their been changes to the API it seem it never enter loop because e.options.length undefined? 
> 
> function getPortIndex(){
> 	var e = parent.document.getElementById("out_portsel");
> 	alert(parent.out_portsel.length);
> 	for (var i=0;i<parent.out_portsel.length;i++){
> 		alert("WTF");
> 			if (e.options[i].value=="FW1884 Control"){ctrlportindex=i; alert(ctrlportindex); break;}
> 					else{alert("nonevalid port");}
> 	}
> }

Here again, I think this code could be factored to be easier to read and verify.

let E = (x)=>parent.document.getElementById(x);

function getPortIndex(){
    let e = E("out_portsel");
    return  e.options.findIndex( (opt)=>opt.value=="FW1884 Control" );
}

I started to write a findfirst() function using .forEach() but after glancing
at online refs I noticed .findIndex() which does all the looping business.
There is a difference here in that my version uses the length of 
e.options[] instead of parent.out_portsel[] but that part doesn't really
make sense to me so I'm not sure if it's important. If they're not the same,
it might be worth investigating that so functions like this can be short
and sweet.

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


#40510

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2021-11-01 15:05 -0700
Message-ID<62f33292-be2f-4d5a-bf4f-824f5cd45c92n@googlegroups.com>
In reply to#40509
måndag 1 november 2021 kl. 17:17:25 UTC+1 skrev luser...@gmail.com:
> On Monday, November 1, 2021 at 4:23:57 AM UTC-5, jonas.t...@gmail.com wrote: 
> > I am pretty sure this code did run a week ago, have their been changes to the API it seem it never enter loop because e.options.length undefined? 
> > 
> > function getPortIndex(){ 
> > var e = parent.document.getElementById("out_portsel"); 
> > alert(parent.out_portsel.length); 
> > for (var i=0;i<parent.out_portsel.length;i++){ 
> > alert("WTF"); 
> > if (e.options[i].value=="FW1884 Control"){ctrlportindex=i; alert(ctrlportindex); break;} 
> > else{alert("nonevalid port");} 
> > } 
> > }
> Here again, I think this code could be factored to be easier to read and verify. 
> 
> let E = (x)=>parent.document.getElementById(x); 
> 
> function getPortIndex(){ 
> let e = E("out_portsel"); 
> return e.options.findIndex( (opt)=>opt.value=="FW1884 Control" ); 
> } 
> 
> I started to write a findfirst() function using .forEach() but after glancing 
> at online refs I noticed .findIndex() which does all the looping business. 
> There is a difference here in that my version uses the length of 
> e.options[] instead of parent.out_portsel[] but that part doesn't really 
> make sense to me so I'm not sure if it's important. If they're not the same, 
> it might be worth investigating that so functions like this can be short 
> and sweet.
Nice.

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


#40511

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2021-11-01 15:10 -0700
Message-ID<e53e7ed2-8cfc-4ae3-a0dc-6d8d9ebaebacn@googlegroups.com>
In reply to#40509
måndag 1 november 2021 kl. 17:17:25 UTC+1 skrev luser...@gmail.com:
> On Monday, November 1, 2021 at 4:23:57 AM UTC-5, jonas.t...@gmail.com wrote: 
> > I am pretty sure this code did run a week ago, have their been changes to the API it seem it never enter loop because e.options.length undefined? 
> > 
> > function getPortIndex(){ 
> > var e = parent.document.getElementById("out_portsel"); 
> > alert(parent.out_portsel.length); 
> > for (var i=0;i<parent.out_portsel.length;i++){ 
> > alert("WTF"); 
> > if (e.options[i].value=="FW1884 Control"){ctrlportindex=i; alert(ctrlportindex); break;} 
> > else{alert("nonevalid port");} 
> > } 
> > }
> Here again, I think this code could be factored to be easier to read and verify. 
> 
> let E = (x)=>parent.document.getElementById(x); 
> 
> function getPortIndex(){ 
> let e = E("out_portsel"); 
> return e.options.findIndex( (opt)=>opt.value=="FW1884 Control" ); 
> } 
> 
> I started to write a findfirst() function using .forEach() but after glancing 
> at online refs I noticed .findIndex() which does all the looping business. 
> There is a difference here in that my version uses the length of 
> e.options[] instead of parent.out_portsel[] but that part doesn't really 
> make sense to me so I'm not sure if it's important. If they're not the same, 
> it might be worth investigating that so functions like this can be short 
> and sweet.
Can't say i like the Javascript syntax though what is the (opt)=> about and why is it necessary?
Why not just  e.options.findIndex( (opt.value=="FW1884 Control" );

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


#40512

Fromluserdroog <luser.droog@gmail.com>
Date2021-11-01 19:24 -0700
Message-ID<5d0d82f9-0dd6-4b73-afb0-d1ad505e28a4n@googlegroups.com>
In reply to#40511
On Monday, November 1, 2021 at 5:10:23 PM UTC-5, jonas.t...@gmail.com wrote:
> måndag 1 november 2021 kl. 17:17:25 UTC+1 skrev luser...@gmail.com:
> > On Monday, November 1, 2021 at 4:23:57 AM UTC-5, jonas.t...@gmail.com wrote: 
> > > I am pretty sure this code did run a week ago, have their been changes to the API it seem it never enter loop because e.options.length undefined? 
> > > 
> > > function getPortIndex(){ 
> > > var e = parent.document.getElementById("out_portsel"); 
> > > alert(parent.out_portsel.length); 
> > > for (var i=0;i<parent.out_portsel.length;i++){ 
> > > alert("WTF"); 
> > > if (e.options[i].value=="FW1884 Control"){ctrlportindex=i; alert(ctrlportindex); break;} 
> > > else{alert("nonevalid port");} 
> > > } 
> > > } 
> > Here again, I think this code could be factored to be easier to read and verify. 
> > 
> > let E = (x)=>parent.document.getElementById(x); 
> > 
> > function getPortIndex(){ 
> > let e = E("out_portsel"); 
> > return e.options.findIndex( (opt)=>opt.value=="FW1884 Control" ); 
> > } 
> > 
> > I started to write a findfirst() function using .forEach() but after glancing 
> > at online refs I noticed .findIndex() which does all the looping business. 
> > There is a difference here in that my version uses the length of 
> > e.options[] instead of parent.out_portsel[] but that part doesn't really 
> > make sense to me so I'm not sure if it's important. If they're not the same, 
> > it might be worth investigating that so functions like this can be short 
> > and sweet.
> Can't say i like the Javascript syntax though what is the (opt)=> about and why is it necessary? 
> Why not just e.options.findIndex( (opt.value=="FW1884 Control" );

That's a good question. I believe it's part of a batch of features added to
IIRC Ecma 5 (and more in 6) to support functional programming.
A lot of the array methods are really nice for replacing loops of various
kinds. But the price is you have to do it "functionally" which means 
passing in a function. It doesn't have to use the array syntax.

You could also write it like:
  e.options.findIndex( function(opt){ return  opt.value=="FW1884 Control"; } );

But the code in middle (the *predicate* here, because it returns a boolean)
has to be wrapped up in a function. I like the arrow syntax because it
feels very lightweight and direct, but not everyone likes it. That's a valid
reaction. It does look weird.

This is a change I had to learn (twice) in my programming life. First in college,
then again years later when I picked it back up as a hobby. The downside is
you never stop hunting bugs, but the bugs get weirder and more interesting.
I've been scratching my head for weeks over a 200 line program in PostScript
that does (tries to do) parsing of regular expressions using parser combinators.
It's only 200 lines, but I can't find the bug! But I don't envy what the task
would be like if the program were 2000 or 20000 lines.

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


#40513

FromJulio Di Egidio <julio@diegidio.name>
Date2021-11-01 23:54 -0700
Message-ID<4654561d-ea56-4512-abfc-b3752739897cn@googlegroups.com>
In reply to#40512
On Tuesday, 2 November 2021 at 03:24:16 UTC+1, luser...@gmail.com wrote:
> On Monday, November 1, 2021 at 5:10:23 PM UTC-5, jonas.t...@gmail.com wrote: 

> > Can't say i like the Javascript syntax though what is the (opt)=> about and why is it necessary? 
> > Why not just e.options.findIndex( (opt.value=="FW1884 Control" );
> That's a good question. I believe it's part of a batch of features added to

It's a stupid question but your answer it's an even worse pile of pure crap:
as usual, your incompetence is second only to your arrogance.

When Dunning-Kruger is a compliment...

*Plonk*

Julio

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


#40514

Fromluserdroog <luser.droog@gmail.com>
Date2021-11-02 05:21 -0700
Message-ID<d7e2a36d-cf5a-4b46-819a-f68a69c0eb6cn@googlegroups.com>
In reply to#40513
On Tuesday, November 2, 2021 at 1:54:20 AM UTC-5, ju...@diegidio.name wrote:
> On Tuesday, 2 November 2021 at 03:24:16 UTC+1, luser...@gmail.com wrote: 
> > On Monday, November 1, 2021 at 5:10:23 PM UTC-5, jonas.t...@gmail.com wrote: 
> 
> > > Can't say i like the Javascript syntax though what is the (opt)=> about and why is it necessary? 
> > > Why not just e.options.findIndex( (opt.value=="FW1884 Control" ); 
> > That's a good question. I believe it's part of a batch of features added to
> It's a stupid question but your answer it's an even worse pile of pure crap: 
> as usual, your incompetence is second only to your arrogance. 
> 
> When Dunning-Kruger is a compliment... 
> 
> *Plonk* 

Dude, chill the fuck out.

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


#40515

FromJon Ribbens <jon+usenet@unequivocal.eu>
Date2021-11-02 12:41 +0000
Message-ID<slrnso2cgi.503.jon+usenet@raven.unequivocal.eu>
In reply to#40514
On 2021-11-02, luserdroog <luser.droog@gmail.com> wrote:
> On Tuesday, November 2, 2021 at 1:54:20 AM UTC-5, ju...@diegidio.name wrote:
>> On Tuesday, 2 November 2021 at 03:24:16 UTC+1, luser...@gmail.com wrote: 
>> > On Monday, November 1, 2021 at 5:10:23 PM UTC-5, jonas.t...@gmail.com wrote: 
>> 
>> > > Can't say i like the Javascript syntax though what is the (opt)=> about and why is it necessary? 
>> > > Why not just e.options.findIndex( (opt.value=="FW1884 Control" ); 
>> > That's a good question. I believe it's part of a batch of features added to
>> It's a stupid question but your answer it's an even worse pile of pure crap: 
>> as usual, your incompetence is second only to your arrogance. 
>> 
>> When Dunning-Kruger is a compliment... 
>> 
>> *Plonk* 
>
> Dude, chill the fuck out.

Don't worry about Julio the Plonker, he just gibbers non-stop
foul-mouthed nonsense into the group. Killfiling him is the
recommended solution.

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


#40516

Fromluserdroog <luser.droog@gmail.com>
Date2021-11-03 16:15 -0700
Message-ID<afaee1a6-3258-4c57-b1eb-d3b7e80e86cfn@googlegroups.com>
In reply to#40515
On Tuesday, November 2, 2021 at 7:42:02 AM UTC-5, Jon Ribbens wrote:
> On 2021-11-02, luserdroog <luser...@gmail.com> wrote: 
> > On Tuesday, November 2, 2021 at 1:54:20 AM UTC-5, ju...@diegidio.name wrote: 
> >> On Tuesday, 2 November 2021 at 03:24:16 UTC+1, luser...@gmail.com wrote: 
> >> > On Monday, November 1, 2021 at 5:10:23 PM UTC-5, jonas.t...@gmail.com wrote: 
> >> 
> >> > > Can't say i like the Javascript syntax though what is the (opt)=> about and why is it necessary? 
> >> > > Why not just e.options.findIndex( (opt.value=="FW1884 Control" ); 
> >> > That's a good question. I believe it's part of a batch of features added to 
> >> It's a stupid question but your answer it's an even worse pile of pure crap: 
> >> as usual, your incompetence is second only to your arrogance. 
> >> 
> >> When Dunning-Kruger is a compliment... 
> >> 
> >> *Plonk* 
> > 
> > Dude, chill the fuck out.
> Don't worry about Julio the Plonker, he just gibbers non-stop 
> foul-mouthed nonsense into the group. Killfiling him is the 
> recommended solution.

You're right. I overreacted. I thought I'd made some progress with Julio in our
last exchange. I apologize for increasing the foul-mouthedness.

[toc] | [prev] | [standalone]


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


csiph-web