Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #37748 > unrolled thread
| Started by | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| First post | 2019-11-11 02:52 -0800 |
| Last post | 2019-11-12 15:46 +0100 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.lang.javascript
End of selected items. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-11-11 02:52 -0800
Re: End of selected items. John G Harris <niam@jghnorth.org.uk.invalid> - 2019-11-11 11:22 +0000
Re: End of selected items. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-11-11 05:58 -0800
Re: End of selected items. Arno Welzel <usenet@arnowelzel.de> - 2019-11-12 15:31 +0100
Re: End of selected items. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-11-12 15:46 +0100
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-11-11 02:52 -0800 |
| Subject | End of selected items. |
| Message-ID | <64be7dde-48ce-4a0a-8ae7-32ecbd9d1399@googlegroups.com> |
An array can hold elements with different types, there is no problem to step thru all elements of an array.
But how do one handle stepping thru an array where you do not know the last element of a certain type?
What is the condition for the increment->, that tells this was the last element?
You can't tell it was the last element until end of array? Should one just scroll thru and find last element index of each type and save at beginning?
I guess that must be done but am not sure, this problem must come up in every database?
//SELECT EVENT TO EDIT
function eventPlus() {
console.log("eventPlus() ");
if (trackEvent < track[editTrack].midiMess.length-1 && (listchoice=="on" || listchoice=="on/off")) {
trackEvent++;
while (track[editTrack].midiMess[trackEvent].data0 < "144" || track[editTrack].midiMess[trackEvent].data0 > "159") {
trackEvent++;
}
if (trackEvent < track[editTrack].midiMess.length-1) {
document.getElementById("chosenEvent").value = trackEvent;
drawTrackX(editTrack, trackEvent);
}
} else if (trackEvent < track[editTrack].midiMess.length-1 && listchoice=="all") {
trackEvent++;
while ( trackEvent < track[editTrack].midiMess.length-1 && track[editTrack].midiMess[trackEvent].data0 > "127" && track[editTrack].midiMess[trackEvent].data0 <"144") {
trackEvent++;
}
if (trackEvent < track[editTrack].midiMess.length) {
document.getElementById("chosenEvent").value = trackEvent;
drawTrackX(editTrack, trackEvent);
}
} else if (trackEvent < track[editTrack].midiMess.length-1 && listchoice=="cc") {
trackEvent++;
while (trackEvent < track[editTrack].midiMess.length && track[editTrack].midiMess[trackEvent].data0 < "128" && track[editTrack].midiMess[trackEvent].data0 >"158")
{
trackEvent++;
}
if (trackEvent < track[editTrack].midiMess.length) {
document.getElementById("chosenEvent").value = trackEvent;
drawTrackX(editTrack, trackEvent);
}
}
}
[toc] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2019-11-11 11:22 +0000 |
| Message-ID | <d3hiset7e3q2oqqemcm10tqemf3n2o4c91@4ax.com> |
| In reply to | #37748 |
On Mon, 11 Nov 2019 02:52:25 -0800 (PST), Jonas Thörnvall <jonas.thornvall@gmail.com> wrote: >An array can hold elements with different types, there is no problem to step thru all elements of an array. > >But how do one handle stepping thru an array where you do not know the last element of a certain type? > >What is the condition for the increment->, that tells this was the last element? >You can't tell it was the last element until end of array? Should one just scroll thru and find last element index of each type and save at beginning? <snip> Do you know which type it is when it's added to the array? If you do then you put its index number in an array (or object) when you do the add. There's a seperate entry for each type. Updating both arrays is best done in a function so you won't forget to do both updates. Afterwards, the second array (or object) holds the last index for each type. If you don't know the type when adding then you have to do a scan of the entries afterwards. John
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-11-11 05:58 -0800 |
| Message-ID | <8a42d4d6-0e51-4379-8991-5865bf4a2b96@googlegroups.com> |
| In reply to | #37749 |
Den måndag 11 november 2019 kl. 12:23:01 UTC+1 skrev John G Harris: > On Mon, 11 Nov 2019 02:52:25 -0800 (PST), Jonas Thörnvall > <jonas.thornvall@gmail.com> wrote: > > >An array can hold elements with different types, there is no problem to step thru all elements of an array. > > > >But how do one handle stepping thru an array where you do not know the last element of a certain type? > > > >What is the condition for the increment->, that tells this was the last element? > >You can't tell it was the last element until end of array? Should one just scroll thru and find last element index of each type and save at beginning? > <snip> > > Do you know which type it is when it's added to the array? If you do > then you put its index number in an array (or object) when you do the > add. There's a seperate entry for each type. Updating both arrays is > best done in a function so you won't forget to do both updates. > Afterwards, the second array (or object) holds the last index for each > type. > > If you don't know the type when adding then you have to do a scan of > the entries afterwards. > > John No i don't think i can check without latency, so i guess i have to scan afterwards. "At start of selection, no problem do it allover because there is nothing timecritical about listing elements".
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2019-11-12 15:31 +0100 |
| Message-ID | <h2vu26Fr5esU1@mid.individual.net> |
| In reply to | #37748 |
On 11.11.19 11:52, Jonas Thörnvall wrote: > An array can hold elements with different types, there is no problem to step thru all elements of an array. > > But how do one handle stepping thru an array where you do not know the last element of a certain type? > > What is the condition for the increment->, that tells this was the last element? You step thru the whole array and just use the element if it is of a certain type and ignore the others. > You can't tell it was the last element until end of array? Should one just scroll thru and find last element index of each type and save at beginning? Yes. > I guess that must be done but am not sure, this problem must come up in every database? In a database one would just not query element types you don't want. For example with an SQL query: select * from articles where location='bookshelf' and NOT: "select * from articles" followed by a script which goes thru the result just to find the last article with the condition "location=='bookshelf'". -- Arno Welzel https://arnowelzel.de
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2019-11-12 15:46 +0100 |
| Message-ID | <XnsAB05A08B7FCE5eejj99@194.109.6.166> |
| In reply to | #37762 |
Arno Welzel <usenet@arnowelzel.de> wrote on 12 Nov 2019 in comp.lang.javascript: > In a database one would just not query element types you don't want. > > For example with an SQL query: > > select * from articles where location='bookshelf' > > and NOT: > > "select * from articles" followed by a script which goes thru the result > just to find the last article with the condition "location=='bookshelf'". In SQL one should look at the top one of an "inversed" order to find the last one, while not trusting an "intrinsic" order. SELECT TOP 1 * FROM [articlesTable] WHERE [locationField] = 'bookshelf' ORDER BY [indexField] DESC And yes, if the engine/browser/infrastructure allows it, WebSQL [or even ADODB Recordset] could be an enjoyable programming diversion. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web