experchange > javascript

Jonas Thörnvall (09-18-18, 11:47 AM)
function eventPlus(trackEvent,recTrack) {
if(trackEvent<track[recTrack].midiMess.length){
trackEvent++;
while (track[recTrack].midiMess[trackEvent].data0=="128"){ trackEvent++;}
document.getElementById("chosenEvent").value=track Event;
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
Jonas Thörnvall (09-18-18, 12:06 PM)
Den tisdag 18 september 2018 kl. 11:47:36 UTC+2 skrev Jonas Thörnvall:
[..]
> 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=track Event;
listTrackX(recTrack,trackEvent);
}
}
}
Jonas Thörnvall (09-18-18, 12:18 PM)
Den tisdag 18 september 2018 kl. 12:06:44 UTC+2 skrev Jonas Thörnvall:
[..]
> }
> }
> }


Or maybe like this
callmyfunction=Search(track[recTrack].midiMess[trackEvent.next].data0==144);
Julio Di Egidio (09-18-18, 12:24 PM)
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
Ben Bacarisse (09-18-18, 12:41 PM)
Jonas Thörnvall <jonas.thornvall> writes:

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


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



And there is also an Array.prototype.findIndex() method a description of
which is linked from the page above.
Julio Di Egidio (09-18-18, 12:49 PM)
On Tuesday, 18 September 2018 12:41:19 UTC+2, Ben Bacarisse wrote:
> Jonas Thörnvall <jonas.thornvall> 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
Julio Di Egidio (09-18-18, 12:56 PM)
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> 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
Jonas Thörnvall (09-18-18, 05:09 PM)
Den tisdag 18 september 2018 kl. 12:41:19 UTC+2 skrev Ben Bacarisse:
> Jonas Thörnvall <jonas.thornvall> writes:
> You might consider using Array.prototype.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?
Jake Jarvis (09-18-18, 06:07 PM)
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:
> 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
Jonas Thörnvall (09-18-18, 06:48 PM)
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:
> Look again at the list of indexOf's parameters


You are correct i am a bit sloppy just looked at the example.
Julio Di Egidio (09-18-18, 07:09 PM)
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:
> 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
Jonas Thörnvall (09-18-18, 07:36 PM)
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:
> 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 tome.
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.
Jonas Thörnvall (09-18-18, 07:48 PM)
Den tisdag 18 september 2018 kl. 19:36:49 UTC+2 skrev Jonas Thörnvall:
[..]
> 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, butmaybe there is a logic behind it.


Well if a method the syntax should probably be.
trackEvent)=track[recTrack].midiMess[trackEvent].data0.==144).find.next;
Jonas Thörnvall (09-18-18, 08:06 PM)
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:
> 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 otherlike 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.
Jonas Thörnvall (09-19-18, 03:23 AM)
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:
> 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 shouldbe 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?

Similar Threads