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


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

Incremental search in array using index, prevent shotover at end?

Started byJonas Thörnvall <jonas.thornvall@gmail.com>
First post2018-09-18 02:47 -0700
Last post2018-09-20 23:27 -0700
Articles 17 — 5 participants

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


Contents

  Incremental search in array using index, prevent shotover at end? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-09-18 02:47 -0700
    Re: Incremental search in array using index, prevent shotover at end? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-09-18 03:06 -0700
      Re: Incremental search in array using index, prevent shotover at end? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-09-18 03:18 -0700
      Re: Incremental search in array using index, prevent shotover at end? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-09-18 11:41 +0100
        Re: Incremental search in array using index, prevent shotover at end? Julio Di Egidio <julio@diegidio.name> - 2018-09-18 03:49 -0700
          Re: Incremental search in array using index, prevent shotover at end? Julio Di Egidio <julio@diegidio.name> - 2018-09-18 03:56 -0700
        Re: Incremental search in array using index, prevent shotover at end? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-09-18 08:09 -0700
          Re: Incremental search in array using index, prevent shotover at end? Jake Jarvis <pig_in_shoes@yahoo.com> - 2018-09-18 18:07 +0200
            Re: Incremental search in array using index, prevent shotover at end? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-09-18 09:48 -0700
              Re: Incremental search in array using index, prevent shotover at end? Julio Di Egidio <julio@diegidio.name> - 2018-09-18 10:09 -0700
            Re: Incremental search in array using index, prevent shotover at end? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-09-18 10:36 -0700
              Re: Incremental search in array using index, prevent shotover at end? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-09-18 10:48 -0700
                Re: Incremental search in array using index, prevent shotover at end? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-09-18 11:06 -0700
                  Re: Incremental search in array using index, prevent shotover at end? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-09-18 18:23 -0700
    Re: Incremental search in array using index, prevent shotover at end? Julio Di Egidio <julio@diegidio.name> - 2018-09-18 03:24 -0700
    Re: Incremental search in array using index, prevent shotover at end? Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2018-09-20 11:11 +0200
      Re: Incremental search in array using index, prevent shotover at end? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-09-20 23:27 -0700

#35600 — Incremental search in array using index, prevent shotover at end?

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-09-18 02:47 -0700
SubjectIncremental search in array using index, prevent shotover at end?
Message-ID<f6da5d85-1588-4ce6-a742-8babf24382c1@googlegroups.com>
function eventPlus(trackEvent,recTrack) {
 if(trackEvent<track[recTrack].midiMess.length){
   trackEvent++;
   while (track[recTrack].midiMess[trackEvent].data0=="128"){ trackEvent++;}
   document.getElementById("chosenEvent").value=trackEvent;
   listTrackX(recTrack,trackEvent);
 }
}

I feel the code is ineherently wrong above, even if i add the "&& trackEvent<track[recTrack].midiMess.length" to the loop.



Example Array
144
128
144
128
144
144
144  
128
128
128


[toc] | [next] | [standalone]


#35601

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-09-18 03:06 -0700
Message-ID<056c11c6-1019-4dc7-8d07-b1b950d11f0b@googlegroups.com>
In reply to#35600
Den tisdag 18 september 2018 kl. 11:47:36 UTC+2 skrev Jonas Thörnvall:
> function eventPlus(trackEvent,recTrack) {
>  if(trackEvent<track[recTrack].midiMess.length){
>    trackEvent++;
>    while (track[recTrack].midiMess[trackEvent].data0=="128"){ trackEvent++;}
>    document.getElementById("chosenEvent").value=trackEvent;
>    listTrackX(recTrack,trackEvent);
>  }
> }
> 
> I feel the code is ineherently wrong above, even if i add the "&& trackEvent<track[recTrack].midiMess.length" to the loop.
> 
> 
> 
> Example Array
> 144
> 128
> 144
> 128
> 144
> 144
> 144  
> 128
> 128
> 128

This code prevents input values from overshooting array but it seem like total overkill to me. I just want the next event of type 144.

Would love some "easy search" syntax, maybe there already is?

callmyfunction=SearchNext(track[recTrack].midiMess[trackEvent].data0==144);
and likewise
callmyfunction=SearchPrevious(track[recTrack].midiMess[trackEvent].data0==144);



function eventPlus() {
 if(trackEvent<track[recTrack].midiMess.length){
   trackEvent++;
   while ( trackEvent<track[recTrack].midiMess.length && track[recTrack].midiMess[trackEvent].data0=="128" ){ trackEvent++;}
   if (trackEvent<track[recTrack].midiMess.length && track[recTrack].midiMess[trackEvent].data0=="144"){
       document.getElementById("chosenEvent").value=trackEvent;
       listTrackX(recTrack,trackEvent);
     }
 }
}

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


#35602

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-09-18 03:18 -0700
Message-ID<599f8839-7c11-4646-abbd-ab7ddda0a191@googlegroups.com>
In reply to#35601
Den tisdag 18 september 2018 kl. 12:06:44 UTC+2 skrev Jonas Thörnvall:
> Den tisdag 18 september 2018 kl. 11:47:36 UTC+2 skrev Jonas Thörnvall:
> > function eventPlus(trackEvent,recTrack) {
> >  if(trackEvent<track[recTrack].midiMess.length){
> >    trackEvent++;
> >    while (track[recTrack].midiMess[trackEvent].data0=="128"){ trackEvent++;}
> >    document.getElementById("chosenEvent").value=trackEvent;
> >    listTrackX(recTrack,trackEvent);
> >  }
> > }
> > 
> > I feel the code is ineherently wrong above, even if i add the "&& trackEvent<track[recTrack].midiMess.length" to the loop.
> > 
> > 
> > 
> > Example Array
> > 144
> > 128
> > 144
> > 128
> > 144
> > 144
> > 144  
> > 128
> > 128
> > 128
> 
> This code prevents input values from overshooting array but it seem like total overkill to me. I just want the next event of type 144.
> 
> Would love some "easy search" syntax, maybe there already is?
> 
> callmyfunction=SearchNext(track[recTrack].midiMess[trackEvent].data0==144);
> and likewise
> callmyfunction=SearchPrevious(track[recTrack].midiMess[trackEvent].data0==144);
> 
> 
> 
> function eventPlus() {
>  if(trackEvent<track[recTrack].midiMess.length){
>    trackEvent++;
>    while ( trackEvent<track[recTrack].midiMess.length && track[recTrack].midiMess[trackEvent].data0=="128" ){ trackEvent++;}
>    if (trackEvent<track[recTrack].midiMess.length && track[recTrack].midiMess[trackEvent].data0=="144"){
>        document.getElementById("chosenEvent").value=trackEvent;
>        listTrackX(recTrack,trackEvent);
>      }
>  }
> }

Or maybe like this
callmyfunction=Search(track[recTrack].midiMess[trackEvent.next].data0==144);

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


#35604

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2018-09-18 11:41 +0100
Message-ID<87sh2784vs.fsf@bsb.me.uk>
In reply to#35601
Jonas Thörnvall <jonas.thornvall@gmail.com> writes:

> Would love some "easy search" syntax, maybe there already is?

You might consider using Array.prototype.find():

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

And there is also an Array.prototype.findIndex() method a description of
which is linked from the page above.

-- 
Ben.

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


#35605

FromJulio Di Egidio <julio@diegidio.name>
Date2018-09-18 03:49 -0700
Message-ID<0cf2b6d3-f2ed-4a29-9a63-b523d5dea849@googlegroups.com>
In reply to#35604
On Tuesday, 18 September 2018 12:41:19 UTC+2, Ben Bacarisse  wrote:
> Jonas Thörnvall <jonas.thornvall@gmail.com> writes:
> 
> > Would love some "easy search" syntax, maybe there already is?
> 
> You might consider using Array.prototype.find():

But keep in mind that it won't support inequalities...

Julio

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


#35606

FromJulio Di Egidio <julio@diegidio.name>
Date2018-09-18 03:56 -0700
Message-ID<0a185318-c35a-4647-a9f1-fb2ca210bf10@googlegroups.com>
In reply to#35605
On Tuesday, 18 September 2018 12:49:33 UTC+2, Julio Di Egidio  wrote:
> On Tuesday, 18 September 2018 12:41:19 UTC+2, Ben Bacarisse  wrote:
> > Jonas Thörnvall <jonas.thornvall@gmail.com> writes:
> > 
> > > Would love some "easy search" syntax, maybe there already is?
> > 
> > You might consider using Array.prototype.find():
> 
> But keep in mind that it won't support inequalities...

Sorry, now I was too quick: of course that's not the case.

Julio

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


#35607

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-09-18 08:09 -0700
Message-ID<785e022a-e005-42f7-9bea-b157a1e339ee@googlegroups.com>
In reply to#35604
Den tisdag 18 september 2018 kl. 12:41:19 UTC+2 skrev Ben Bacarisse:
> Jonas Thörnvall <jonas.thornvall@gmail.com> writes:
> 
> > Would love some "easy search" syntax, maybe there already is?
> 
> You might consider using Array.prototype.find():
> 
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
> 
> And there is also an Array.prototype.findIndex() method a description of
> which is linked from the page above.
> 
> -- 
> Ben.

Hello Ben, i am not sure it is applicable to the case. Often in arrays you are at a specific index, and you want the next occurence of something starting from that index, this seem more like a general search to me?

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


#35609

FromJake Jarvis <pig_in_shoes@yahoo.com>
Date2018-09-18 18:07 +0200
Message-ID<pnr7s6$qt3$1@dont-email.me>
In reply to#35607
Am 18.09.2018 um 17:09 schrieb Jonas Thörnvall:
> Den tisdag 18 september 2018 kl. 12:41:19 UTC+2 skrev Ben Bacarisse:
>> Jonas Thörnvall <jonas.thornvall@gmail.com> writes:
>>
>>> Would love some "easy search" syntax, maybe there already is?
>>
>> You might consider using Array.prototype.find():
>>
>> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
>>
>> And there is also an Array.prototype.findIndex() method a description of
>> which is linked from the page above.
>>
>> -- 
>> Ben.
> 
> Hello Ben, i am not sure it is applicable to the case. Often in arrays you are at a specific index, and you want the next occurence of something starting from that index, this seem more like a general search to me?
> 

Look again at the list of indexOf's parameters

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


#35610

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-09-18 09:48 -0700
Message-ID<ae2088cc-263a-4219-8753-0476e24b1c7f@googlegroups.com>
In reply to#35609
Den tisdag 18 september 2018 kl. 18:07:41 UTC+2 skrev Jake Jarvis:
> Am 18.09.2018 um 17:09 schrieb Jonas Thörnvall:
> > Den tisdag 18 september 2018 kl. 12:41:19 UTC+2 skrev Ben Bacarisse:
> >> Jonas Thörnvall <jonas.thornvall@gmail.com> writes:
> >>
> >>> Would love some "easy search" syntax, maybe there already is?
> >>
> >> You might consider using Array.prototype.find():
> >>
> >> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
> >>
> >> And there is also an Array.prototype.findIndex() method a description of
> >> which is linked from the page above.
> >>
> >> -- 
> >> Ben.
> > 
> > Hello Ben, i am not sure it is applicable to the case. Often in arrays you are at a specific index, and you want the next occurence of something starting from that index, this seem more like a general search to me?
> > 
> 
> Look again at the list of indexOf's parameters

You are correct i am a bit sloppy just looked at the example.

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


#35611

FromJulio Di Egidio <julio@diegidio.name>
Date2018-09-18 10:09 -0700
Message-ID<62963489-acc0-4618-9825-9cc361f95d5b@googlegroups.com>
In reply to#35610
On Tuesday, 18 September 2018 18:48:33 UTC+2, Jonas Thörnvall  wrote:
> Den tisdag 18 september 2018 kl. 18:07:41 UTC+2 skrev Jake Jarvis:
> > Am 18.09.2018 um 17:09 schrieb Jonas Thörnvall:
> > > Den tisdag 18 september 2018 kl. 12:41:19 UTC+2 skrev Ben Bacarisse:
> > >> Jonas Thörnvall <jonas.thornvall@gmail.com> writes:
> > >>
> > >>> Would love some "easy search" syntax, maybe there already is?
> > >>
> > >> You might consider using Array.prototype.find():
> > >>
> > >> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
> > >>
> > >> And there is also an Array.prototype.findIndex() method a description of
> > >> which is linked from the page above.
> > > 
> > > Hello Ben, i am not sure it is applicable to the case. Often in arrays you are at a specific index, and you want the next occurence of something starting from that index, this seem more like a general search to me?
> > 
> > Look again at the list of indexOf's parameters
> 
> You are correct i am a bit sloppy just looked at the example.

In general, he is not correct, Array.find is of course not as general as an
arbitrary loop, where you can also skip indexes or consider them in any order
you like: Array.find abstracts from the exit condition, but implements a basic
iteration logic.

And the difference seems still relevant in your specific case, since you
do not start the search from index zero, and most probably cannot...

Julio

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


#35612

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-09-18 10:36 -0700
Message-ID<6ac90ddb-aeb4-4fda-96f9-a23e5109cd44@googlegroups.com>
In reply to#35609
Den tisdag 18 september 2018 kl. 18:07:41 UTC+2 skrev Jake Jarvis:
> Am 18.09.2018 um 17:09 schrieb Jonas Thörnvall:
> > Den tisdag 18 september 2018 kl. 12:41:19 UTC+2 skrev Ben Bacarisse:
> >> Jonas Thörnvall <jonas.thornvall@gmail.com> writes:
> >>
> >>> Would love some "easy search" syntax, maybe there already is?
> >>
> >> You might consider using Array.prototype.find():
> >>
> >> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
> >>
> >> And there is also an Array.prototype.findIndex() method a description of
> >> which is linked from the page above.
> >>
> >> -- 
> >> Ben.
> > 
> > Hello Ben, i am not sure it is applicable to the case. Often in arrays you are at a specific index, and you want the next occurence of something starting from that index, this seem more like a general search to me?
> > 
> 
> Look again at the list of indexOf's parameters

Actually i find the "function(element)" part syntax, quite unintuitive, what is it supposed to mean?
I do get that find is a method upon arrays, but the rest seem so strange to me.
And i really do not understand the syntax to neither get a "data object?" within array, and i do not understand where to make the function call

 listTrackX(recTrack, trackEvent) = track[recTrack].midiMess[trackEvent].data0.find(function(midiMess[trackEvent]) {
  return trackEvent == 144;
});

As you see this is quite confusing to me?
I have not tried it because i suspect it is not the correct syntax.
And  i wonder why?


Why not a more simple syntax?
listTrackX(recTrack, trackEvent)=find.track[recTrack].midiMess[trackEvent].data0.==144);
But that probably return same index you are on so.


or listTrackX(recTrack, trackEvent)=find.next.track[recTrack].midiMess[trackEvent].data0.==144);

If find the syntax so very strange, "contrieved" i guess is the word, but maybe there is a logic behind it.






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


#35613

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-09-18 10:48 -0700
Message-ID<5d15d185-2b28-4e7a-aa67-022ab10dd8d8@googlegroups.com>
In reply to#35612
Den tisdag 18 september 2018 kl. 19:36:49 UTC+2 skrev Jonas Thörnvall:
> Den tisdag 18 september 2018 kl. 18:07:41 UTC+2 skrev Jake Jarvis:
> > Am 18.09.2018 um 17:09 schrieb Jonas Thörnvall:
> > > Den tisdag 18 september 2018 kl. 12:41:19 UTC+2 skrev Ben Bacarisse:
> > >> Jonas Thörnvall <jonas.thornvall@gmail.com> writes:
> > >>
> > >>> Would love some "easy search" syntax, maybe there already is?
> > >>
> > >> You might consider using Array.prototype.find():
> > >>
> > >> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
> > >>
> > >> And there is also an Array.prototype.findIndex() method a description of
> > >> which is linked from the page above.
> > >>
> > >> -- 
> > >> Ben.
> > > 
> > > Hello Ben, i am not sure it is applicable to the case. Often in arrays you are at a specific index, and you want the next occurence of something starting from that index, this seem more like a general search to me?
> > > 
> > 
> > Look again at the list of indexOf's parameters
> 
> Actually i find the "function(element)" part syntax, quite unintuitive, what is it supposed to mean?
> I do get that find is a method upon arrays, but the rest seem so strange to me.
> And i really do not understand the syntax to neither get a "data object?" within array, and i do not understand where to make the function call
> 
>  listTrackX(recTrack, trackEvent) = track[recTrack].midiMess[trackEvent].data0.find(function(midiMess[trackEvent]) {
>   return trackEvent == 144;
> });
> 
> As you see this is quite confusing to me?
> I have not tried it because i suspect it is not the correct syntax.
> And  i wonder why?
> 
> 
> Why not a more simple syntax?
> listTrackX(recTrack, trackEvent)=find.track[recTrack].midiMess[trackEvent].data0.==144);
> But that probably return same index you are on so.
> 
> 
> or listTrackX(recTrack, trackEvent)=find.next.track[recTrack].midiMess[trackEvent].data0.==144);
> 
> If find the syntax so very strange, "contrieved" i guess is the word, but maybe there is a logic behind it.

Well if a method the syntax should probably be.
trackEvent)=track[recTrack].midiMess[trackEvent].data0.==144).find.next;

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


#35614

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-09-18 11:06 -0700
Message-ID<1fd4184b-8390-4f66-92f3-368fd21f5686@googlegroups.com>
In reply to#35613
Den tisdag 18 september 2018 kl. 19:48:24 UTC+2 skrev Jonas Thörnvall:
> Den tisdag 18 september 2018 kl. 19:36:49 UTC+2 skrev Jonas Thörnvall:
> > Den tisdag 18 september 2018 kl. 18:07:41 UTC+2 skrev Jake Jarvis:
> > > Am 18.09.2018 um 17:09 schrieb Jonas Thörnvall:
> > > > Den tisdag 18 september 2018 kl. 12:41:19 UTC+2 skrev Ben Bacarisse:
> > > >> Jonas Thörnvall <jonas.thornvall@gmail.com> writes:
> > > >>
> > > >>> Would love some "easy search" syntax, maybe there already is?
> > > >>
> > > >> You might consider using Array.prototype.find():
> > > >>
> > > >> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
> > > >>
> > > >> And there is also an Array.prototype.findIndex() method a description of
> > > >> which is linked from the page above.
> > > >>
> > > >> -- 
> > > >> Ben.
> > > > 
> > > > Hello Ben, i am not sure it is applicable to the case. Often in arrays you are at a specific index, and you want the next occurence of something starting from that index, this seem more like a general search to me?
> > > > 
> > > 
> > > Look again at the list of indexOf's parameters
> > 
> > Actually i find the "function(element)" part syntax, quite unintuitive, what is it supposed to mean?
> > I do get that find is a method upon arrays, but the rest seem so strange to me.
> > And i really do not understand the syntax to neither get a "data object?" within array, and i do not understand where to make the function call
> > 
> >  listTrackX(recTrack, trackEvent) = track[recTrack].midiMess[trackEvent].data0.find(function(midiMess[trackEvent]) {
> >   return trackEvent == 144;
> > });
> > 
> > As you see this is quite confusing to me?
> > I have not tried it because i suspect it is not the correct syntax.
> > And  i wonder why?
> > 
> > 
> > Why not a more simple syntax?
> > listTrackX(recTrack, trackEvent)=find.track[recTrack].midiMess[trackEvent].data0.==144);
> > But that probably return same index you are on so.
> > 
> > 
> > or listTrackX(recTrack, trackEvent)=find.next.track[recTrack].midiMess[trackEvent].data0.==144);
> > 
> > If find the syntax so very strange, "contrieved" i guess is the word, but maybe there is a logic behind it.
> 
> Well if a method the syntax should probably be.
> trackEvent)=track[recTrack].midiMess[trackEvent].data0.==144).find.next;

This syntax would have been a no brainer even to me.
listTrackX(recTrack, trackEvent)=find.next(track[recTrack].midiMess[trackEvent].data0.==144){ return trackEvent}; 

Here find used method and next is sub to method to it, there could be other like previous.

We pass an array to the methods and when the terms fullfilled we return trackEvent and make the functoin call. I do not even see why a return should be necessary.  

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


#35615

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-09-18 18:23 -0700
Message-ID<f3fa019b-64e6-44b9-a5e4-60ad0938ce35@googlegroups.com>
In reply to#35614
Den tisdag 18 september 2018 kl. 20:06:21 UTC+2 skrev Jonas Thörnvall:
> Den tisdag 18 september 2018 kl. 19:48:24 UTC+2 skrev Jonas Thörnvall:
> > Den tisdag 18 september 2018 kl. 19:36:49 UTC+2 skrev Jonas Thörnvall:
> > > Den tisdag 18 september 2018 kl. 18:07:41 UTC+2 skrev Jake Jarvis:
> > > > Am 18.09.2018 um 17:09 schrieb Jonas Thörnvall:
> > > > > Den tisdag 18 september 2018 kl. 12:41:19 UTC+2 skrev Ben Bacarisse:
> > > > >> Jonas Thörnvall <jonas.thornvall@gmail.com> writes:
> > > > >>
> > > > >>> Would love some "easy search" syntax, maybe there already is?
> > > > >>
> > > > >> You might consider using Array.prototype.find():
> > > > >>
> > > > >> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
> > > > >>
> > > > >> And there is also an Array.prototype.findIndex() method a description of
> > > > >> which is linked from the page above.
> > > > >>
> > > > >> -- 
> > > > >> Ben.
> > > > > 
> > > > > Hello Ben, i am not sure it is applicable to the case. Often in arrays you are at a specific index, and you want the next occurence of something starting from that index, this seem more like a general search to me?
> > > > > 
> > > > 
> > > > Look again at the list of indexOf's parameters
> > > 
> > > Actually i find the "function(element)" part syntax, quite unintuitive, what is it supposed to mean?
> > > I do get that find is a method upon arrays, but the rest seem so strange to me.
> > > And i really do not understand the syntax to neither get a "data object?" within array, and i do not understand where to make the function call
> > > 
> > >  listTrackX(recTrack, trackEvent) = track[recTrack].midiMess[trackEvent].data0.find(function(midiMess[trackEvent]) {
> > >   return trackEvent == 144;
> > > });
> > > 
> > > As you see this is quite confusing to me?
> > > I have not tried it because i suspect it is not the correct syntax.
> > > And  i wonder why?
> > > 
> > > 
> > > Why not a more simple syntax?
> > > listTrackX(recTrack, trackEvent)=find.track[recTrack].midiMess[trackEvent].data0.==144);
> > > But that probably return same index you are on so.
> > > 
> > > 
> > > or listTrackX(recTrack, trackEvent)=find.next.track[recTrack].midiMess[trackEvent].data0.==144);
> > > 
> > > If find the syntax so very strange, "contrieved" i guess is the word, but maybe there is a logic behind it.
> > 
> > Well if a method the syntax should probably be.
> > trackEvent)=track[recTrack].midiMess[trackEvent].data0.==144).find.next;
> 
> This syntax would have been a no brainer even to me.
> listTrackX(recTrack, trackEvent)=find.next(track[recTrack].midiMess[trackEvent].data0.==144){ return trackEvent}; 
> 
> Here find used method and next is sub to method to it, there could be other like previous.
> 
> We pass an array to the methods and when the terms fullfilled we return trackEvent and make the functoin call. I do not even see why a return should be necessary.

doSomething()=find.next.(track[recTrack].midiMess[trackEvent].data0.==144)        
find.previous

find.biggest(track[recTrack].midiMess.data0)
find.smallest

find.last(track[recTrack].midiMess.data0)


arr1=find.all>144(track[recTrack].midiMess.data0)
find.all<
find.all==
find.all!=

arr1=find.range[32,67]
arr1=find.!range[32,67]

Yes i know i am dreaming, but it seem to me like the protocol they follow writing the syntax for javascript have become gradually more and more insane, because is simply not logical?

It looks like thrown together strings, like a meta version of blip blop programming. Yeah thrown together strings randomly or to a pattern that just not have any logical meaning outside the programming language?
     
Generally i do not read much code.
So today i looked abit for midi code, and i see things i do not quite understand i can guess they are equal to functions, but i have not idea.

someName:function(){},

WTF is it just a function but using some contrieved syntax? 

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


#35603

FromJulio Di Egidio <julio@diegidio.name>
Date2018-09-18 03:24 -0700
Message-ID<7e997255-1ecf-42dc-9bb5-f707de259025@googlegroups.com>
In reply to#35600
On Tuesday, 18 September 2018 11:47:36 UTC+2, Jonas Thörnvall  wrote:

> I feel the code is ineherently wrong above

Guessing on what you'd consider correct:

function eventPlus(trackEvent, recTrack) {
  var midiMess = track[recTrack].midiMess;
  while (trackEvent < midiMess.length) {
    if (midiMess[trackEvent].data0 !== "128") {
      document.getElementById("chosenEvent").value = trackEvent;
      listTrackX(recTrack, trackEvent);
      break;
    }
    ++trackEvent;
  }
}

where I am assuming data0 is a string, otherwise that comparison needs fixing.

That said, use spaces and, overall, make the code clean and readable, not short.

HTH,

Julio

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


#35617

FromHans-Georg Michna <hans-georgNoEmailPlease@michna.com>
Date2018-09-20 11:11 +0200
Message-ID<g7o6qd5vvnd8vg9declhv3456tmqato0l7@4ax.com>
In reply to#35600
Just by the way, not exactly related to the problem given here:

In some special cases it can lead to shorter or safer program
code to use a method that most airports use on their runways,
the overrun area. At paved runways there are usually clear, flat
grass strips on either end of the runway. They have the purpose
of giving aeroplanes some extra space if something goes wrong.
That has given me the idea.

In programming, the method is to give an array one or a few
cells behind the intended end. This gives you the opportunity to
check for overruns by looking at the content of each cell and
detecting the overrun, if these extra cells are filled with
something that can easily be recognized, like undefined, null,
or whatever is easy to distinguish.

In some cases this can make a program shorter and simpler. In
some other cases, like programs that are too complex to prove
that a loop actually ends, an overrun area can make an algorithm
safe.

I'm not saying that this is proper for the case on hand. I am
also aware that this method looks a bit stupid at first. (:-)

Hans-Georg

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


#35619

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-09-20 23:27 -0700
Message-ID<5e50aa67-aedd-4477-9b05-8e7eb25df3e3@googlegroups.com>
In reply to#35617
Den torsdag 20 september 2018 kl. 11:11:49 UTC+2 skrev Hans-Georg Michna:
> Just by the way, not exactly related to the problem given here:
> 
> In some special cases it can lead to shorter or safer program
> code to use a method that most airports use on their runways,
> the overrun area. At paved runways there are usually clear, flat
> grass strips on either end of the runway. They have the purpose
> of giving aeroplanes some extra space if something goes wrong.
> That has given me the idea.
> 
> In programming, the method is to give an array one or a few
> cells behind the intended end. This gives you the opportunity to
> check for overruns by looking at the content of each cell and
> detecting the overrun, if these extra cells are filled with
> something that can easily be recognized, like undefined, null,
> or whatever is easy to distinguish.
> 
> In some cases this can make a program shorter and simpler. In
> some other cases, like programs that are too complex to prove
> that a loop actually ends, an overrun area can make an algorithm
> safe.
> 
> I'm not saying that this is proper for the case on hand. I am
> also aware that this method looks a bit stupid at first. (:-)
> 
> Hans-Georg

Yeah but then you get the problem when you update array, looking for which elementslots that are null slots or adjust the couunter when pushing a new one.

[toc] | [prev] | [standalone]


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


csiph-web