Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #32643
| Newsgroups | comp.lang.javascript |
|---|---|
| Date | 2017-02-18 04:46 -0800 |
| References | <bcd07ea6-93e9-4544-bb05-e09ff1e0e5fa@googlegroups.com> <d9e53f7a-56bb-4c63-8d86-bf9d986404b1@googlegroups.com> <f6b5c3dc-872f-4c6b-ade4-44d523718e15@googlegroups.com> |
| Message-ID | <dc53c610-705e-4e48-b03d-d5b5fe515e90@googlegroups.com> (permalink) |
| Subject | Re: Programming strategies |
| From | jonas.thornvall@gmail.com |
Den fredag 17 februari 2017 kl. 12:39:36 UTC+1 skrev jonas.t...@gmail.com:
> Den fredag 17 februari 2017 kl. 11:22:33 UTC+1 skrev jonas.t...@gmail.com:
> > Den torsdag 16 februari 2017 kl. 10:53:49 UTC+1 skrev jonas.t...@gmail.com:
> > > I have a script using arrays where each entry points to x other array entries.
> > >
> > > I think i made the mistake to led the element index itself represent the node number/index.
> > >
> > > Since i autogenerated my graph and nodes i did not really think i thru. But now that i started to build a simple edit tool for the graph the problem become appearant.
> > >
> > > When i remove a node splice all following nodes get relabeled, so the linking of nodes totally become garbeled up.
> > >
> > > I could enforce a label/attribute called nodeindex upon the array that is probably easy to achieve, or i could do a reorder of the linkings it seem alot more job.
> > >
> > > This type of problem must been common in the old register days with use of multidimensional arrays, how was it solved back then and how is it solved today with objectoriented programming?
> > >
> > > Is there some objectoriented approach that make these kind of index issued problematics dissapear?
> >
> > I've seen suggestions that one should not delete the element, just set the element to null. I don't think that is so nice but it probably easiest way for me to get away with my mistake. Probably that is how it was handled in the structured programming era. And since i really use printnode rather than the actual array at printout on canvas maybe i do not even need to null it just set a flag on element that let printout know it is not for use.
> >
> > Right now it seem like the easiest option.
> >
> > Can object oriented languages be smart and understand how elements and their attributes fit together and automatically solve issues like this?
>
> well of course i need to erase any linking to it, but that is what to expect.
The strategy work good so remove nodes no problem, but i have problem with splice subarray element could someone help me howto do it, i can't find examples?
function removeNode(){
for(var t = 0; t < nodes; t ++ )
{
if (mouseDown.x >= arr[t].rposX && mouseDown.x <= (arr[t].rposX + arr[t].rwidth) && mouseDown.y >= arr[t].rposY && mouseDown.y <= (arr[t].rposY + arr[t].rheigth))
{
if (t > -1) {
//alert("removeNode");
arr[t].print=false;
for (var s=0;s<arr[t].nodelinks.length;s++){
remove=arr[t].nodelinks[s];
arr[remove].nodelinks[t].splice(remove,1); <--------SYNTAX ERROR
}
}
}
}
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Programming strategies jonas.thornvall@gmail.com - 2017-02-16 01:53 -0800
Re: Programming strategies jonas.thornvall@gmail.com - 2017-02-17 02:22 -0800
Re: Programming strategies jonas.thornvall@gmail.com - 2017-02-17 03:39 -0800
Re: Programming strategies jonas.thornvall@gmail.com - 2017-02-18 04:46 -0800
Re: Programming strategies jonas.thornvall@gmail.com - 2017-02-18 05:03 -0800
Re: Programming strategies jonas.thornvall@gmail.com - 2017-02-18 05:20 -0800
Re: Programming strategies jonas.thornvall@gmail.com - 2017-02-18 05:34 -0800
Re: Programming strategies jonas.thornvall@gmail.com - 2017-02-18 05:58 -0800
Re: Programming strategies jonas.thornvall@gmail.com - 2017-02-18 07:16 -0800
Re: Programming strategies jonas.thornvall@gmail.com - 2017-02-18 12:14 -0800
csiph-web