html table dynamic dimensions that track a for loop

  • Thread starter murrayatuptowngallery
  • Start date
M

murrayatuptowngallery

After a few searches & inquiries here, I have a method of generating an
html table populated with results of equations that works and wasn't
too far up a learning curve for me, thanks to a helpful
respondent/poster here...

<script type="text/javascript">
var AAA = new Array(4)

AAA[0] = 2*0.1*Math.round(10*Math.log(32)/Math.log(2))
AAA[1] = 2*0.1*Math.round(10*Math.log(16)/Math.log(2))
AAA[2] = 2*0.1*Math.round(10*Math.log(8)/Math.log(2))
AAA[3] = 2*0.1*Math.round(10*Math.log(5.656)/Math.log(2))


theTable='<table border="5"><tr><td>';
theTable+=AAA[0];
theTable+='</td><td>';
theTable+=AAA[1];
theTable+='</td></tr><tr><td>';
theTable+=AAA[2];
theTable+='</td><td>';
theTable+=AAA[3];
theTable+='</td></tr></table>';
document.write(theTable);

</script>


This is a fixed length example. In use, one selects a variable that
determines how many results are generated, using a for-loop, choosing
the range and a couple choices of increment (1, 1/2, 1/3).

Are there any implicit reasons why the array above could not be made
dynamic to track the for loop variable?

I did some searching first as is always recommended, but that seems to
be a never-ending chase for the right words to use in a question...I
DID look, but am apparently searching for the wrong keywords.

Thanks

Murray
 
T

Thomas 'PointedEars' Lahn

murrayatuptowngallery said:
After a few searches & inquiries here, I have a method of generating an
html table populated with results of equations that works and wasn't
too far up a learning curve for me, thanks to a helpful
respondent/poster here...

Why don't you continue the thread you are referring to? I, for
one, don't know what particular poster you are referring to.
var AAA = new Array(4)

In JS/ECMAScript, arrays, as any objects, are dynamic by default, you don't
have to specify the number of elements you wish to store in it. Thanks to
Murphy's Law, depending on the implementation, the above could make you end
up with an array that has only one element (that is later overwritten
anyway) with the number value 4.
AAA[0] = 2*0.1*Math.round(10*Math.log(32)/Math.log(2))
AAA[1] = 2*0.1*Math.round(10*Math.log(16)/Math.log(2))
AAA[2] = 2*0.1*Math.round(10*Math.log(8)/Math.log(2))
AAA[3] = 2*0.1*Math.round(10*Math.log(5.656)/Math.log(2))

Why not

AAA = new Array(
0.2*Math.round(10*Math.log(32)/Math.log(2)),
0.2*Math.round(10*Math.log(16)/Math.log(2)),
0.2*Math.round(10*Math.log(8)/Math.log(2)),
0.2*Math.round(10*Math.log(5.656)/Math.log(2)));

?

Why computed values anyway?
theTable='<table border="5"><tr><td>';
theTable+=AAA[0];
theTable+='</td><td>';
theTable+=AAA[1];
theTable+='</td></tr><tr><td>';
theTable+=AAA[2];
theTable+='</td><td>';
theTable+=AAA[3];
theTable+='</td></tr></table>';

Do you really understand how many String objects are created in the process?
document.write(theTable);

document.write(new Array(
'<table border="5"><tr><td>',
AAA[0],
'</td><td>',
AAA[1],
'</td></tr><tr><td>',
AAA[2],
'</td><td>',
AAA[3],
'</td></tr></table>').join(""));

BTW, I prefer the Array literal syntax: `[element1, element2, ...]'.
</script>

This is a fixed length example. In use, one selects a variable that
determines how many results are generated, using a for-loop, choosing
the range and a couple choices of increment (1, 1/2, 1/3).

So you should post the _used_ code.
Are there any implicit reasons why the array above could not be made
dynamic to track the for loop variable?

No, unless the language implementation is really very b0rken.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Thomas said:
murrayatuptowngallery said:
var AAA = new Array(4)

In JS/ECMAScript, arrays, as any objects, are dynamic by default, [...]

I should have written "_core_ objects". Host objects are
allowed to be static. However, Array is a core object.


PointedEars
 
M

murrayatuptowngallery

Well, P-E, you have helped me in that past. Thank you again. I don't
remember who helped me with what or even what solutions I mimicked.
This project has been traveling around in a backpack waitign for spare
time & often gets shelved for other priorities.

The complete code does not yet exist. I am tackling each feature one at
a time and usually spin off an analogous fragment that is less messy to
learn a technique. If it works, I continue the messy part along the
lines of the solution. Sometimes I can't figure it out and compromise
with something simpler. Probably not vey elegant logic, but I feel
safer adhering to deprecated or near-deprecated methods so I don't use
something that only works with certain browsers. The above statement
doesn't guarantee anything, but it's just a guide.

This whole thing is much messier than I allude to. One might recommend
I do it a different way. I don't need to prove I can write canonical
efficient code. This is survival-skill coding. It's one of those
projects that people will question why bother? Just something I want to
do. Keeps me off the street, as it were.

The reason for calculated content is the whole application is an
application-specific calculator. User enters some parameters, script
determines some basic subsequent results then generates a table of raw
numbers plus, if desired, extrapolated, corrected and curve-fitted data
based on a couple different accepted models, also choices selected
initially. The correction terms are 3rd-order polynomials stored in
another set of arrays.

The whole thing is alot simpler in a spreadsheet, but the people I
intend to share this with will probably only evaluate it if it is
nearly completely automated other than some radio buttons, drop-downs
etc.

The inelegant method of leaving the equations unsimplified reminds me
which equations had an exponent 'brought down as a multiplier' as
properties of logarithmic manipulation.

BTW, to give you some perspective for the prehistoric approach to my
coding, the last programming class I had was punch-card Fortran,
preceded by time-share-computer BASIC using an acoustic telephone modem
(I'm not counting a couple microprocessor classes). Someday I'll take a
C class or learn it on my own...some...day...

That's why some of the pre-searching and latest-accepted-methology
recommendations drown me in additional parallel learning curves.

I looked at the jibbering faq to try and pick up on what etiquette I
may have breached (that seemed to be your implication), but there's
more stuff in there than I can assimilate in one visit.

OT (again), I need to figure out how to log in here without my naked
email address because it just advertises 'open season' for spam. I get
piles of it shortly after each post.

Thanks again

Murray
 
T

Thomas 'PointedEars' Lahn

murrayatuptowngallery said:
Well, P-E, you have helped me in that past. Thank you again.

You're welcome.
I don't remember who helped me with what or even what solutions I
mimicked.
ACK

This project has been traveling around in a backpack waitign for spare
time & often gets shelved for other priorities.

The complete code does not yet exist.

Does not matter, the relevant snippet will/would have suffice(d).
I am tackling each feature one at a time and usually spin off an analogous
fragment that is less messy to learn a technique. If it works, I continue
the messy part along the lines of the solution. Sometimes I can't figure
it out and compromise with something simpler. Probably not vey elegant
logic, but I feel safer adhering to deprecated or near-deprecated methods
so I don't use something that only works with certain browsers. The above
statement doesn't guarantee anything, but it's just a guide.

However, if you expect to produce viable code, looking into documentation
like language references and specifications is a must. Fantasy code will
not get you very far, it seldom works and almost always breaks.
This is survival-skill coding. It's one of those projects that people will
question why bother? Just something I want to do. Keeps me off the street,
as it were.

I understand completely, I am in the same position regarding other
languages.
The inelegant method of leaving the equations unsimplified reminds me
which equations had an exponent 'brought down as a multiplier' as
properties of logarithmic manipulation.

You should be aware that this increases calculation time which is
probably not desired. Probably a decent comment will do instead.
BTW, to give you some perspective for the prehistoric approach to my
coding, the last programming class I had was punch-card Fortran,
preceded by time-share-computer BASIC using an acoustic telephone modem
(I'm not counting a couple microprocessor classes). Someday I'll take a
C class or learn it on my own...some...day...

You know, I have developed only a basic understanding of C(++) and almost
no practical experience in it yet. Came from a BASIC dialect on GDR's Z80
clone (called KC 85/3[1]), which saved programs on audio tapes(!), to Turbo
Pascal to Delphi (and a little bit C[++]), had a short-lived professional
relationship with VBA, then moved on to Web development, including
JS/ECMAScript, and to other languages like (ba)sh and Tcl/expect, which I
nevertheless happen to learn very quickly :) I think my next big language
projects will be _really_ learning Perl, and Python.
That's why some of the pre-searching and latest-accepted-methology
recommendations drown me in additional parallel learning curves.
ACK

I looked at the jibbering faq to try and pick up on what etiquette I
may have breached (that seemed to be your implication), but there's
more stuff in there than I can assimilate in one visit.

You referred to another thread but you did not provide a message ID or
simply continued that thread. I assumed that you remembered the thread
and person you referred to; as that is not so, I think it does not matter
anymore.

However, it would be kind of you if you quoted the minimum of what you
are referring to and then provide attribution as to who wrote what,
see <URL:http://jibbering.com/faq/faq_notes/pots1.html#ps1Marg> and
OT (again), I need to figure out how to log in here without my naked
email address

Hopefully not, because that would violate (Proposed) Standards, particularly
RFC1036 and RFC2822, let alone it would mean a disregardment of Netiquette
(as people may want to contact you privately for both your own and the
newsgroup's good).
because it just advertises 'open season' for spam. I get piles of it
shortly after each post.

Use an (existing, heavy-filtered, seldom-but-not-never-read) spam sink for
From address and an often-read (still spam-filtered) address for Reply-To,
like I do. If that is not possible, do not use Google Groups but a decent
newsreader program, as I would recommend to you anyway (Mozilla Thunderbird
on Windows, KNode on GNU/Linux). Most notably, Thunderbird Mail includes a
Bayesian (trainable [gr?]) spam filter that takes the spam the server-side
filter ignored; see <URL:http://www.paulgraham.com/spam.html>.

And do not hesitate to send _courteous_ complaint e-mails to the ISPs of
spammers (see e.g. X-Complaints-To headers and `whois`) so that they kick
those users (only in their back, if necessary :)), and notify admins of
Open Relays (see Received headers and `whois`) that they configure them
accordingly; use public real-time blacklists
(<URL:http://www.email-policy.com/Spam-black-lists.htm>) if possible.

In retrospect of now almost 5 years of Usenet experience, that approach
appears to me to be the best one, avoiding most of the spam while helping
to preserve the workings of the Net. See also

<URL:http://www.interhack.net/pubs/munging-harmful/>


\V/ PointedEars
_______________
[1] <http://en.wikipedia.org/wiki/KC_85>
 
D

Dr John Stockton

JRS: In article <[email protected]>,
dated Thu, 17 Nov 2005 02:15:03, seen in
murrayatuptowngallery said:
<script type="text/javascript">
var AAA = new Array(4)

AAA[0] = 2*0.1*Math.round(10*Math.log(32)/Math.log(2))
AAA[1] = 2*0.1*Math.round(10*Math.log(16)/Math.log(2))
AAA[2] = 2*0.1*Math.round(10*Math.log(8)/Math.log(2))
AAA[3] = 2*0.1*Math.round(10*Math.log(5.656)/Math.log(2))


theTable='<table border="5"><tr><td>';
theTable+=AAA[0];
theTable+='</td><td>';
theTable+=AAA[1];
theTable+='</td></tr><tr><td>';
theTable+=AAA[2];
theTable+='</td><td>';
theTable+=AAA[3];
theTable+='</td></tr></table>';
document.write(theTable);

</script>


Consider :

<script type="text/javascript">

function AAA(K) { return 2*0.1*Math.round(10*Math.log(K)/Math.log(2)) }

var AA = [[32, 16], [8, 5.656, 1.414]]

T = '<table border="5"><tr><td>';
for (J=0 ; J<AA.length; J++) { AAJ = AA[J]
T += "<tr>"
for (K=0 ; K<AAJ.length ; K++)
T += "<td>" + "AAA(" + AAJ[K] + ") = " + AAA(AAJ[K]) + "<\/td>"
T += "<\/tr>" }
T += '<\/table>';
document.write(T);

</script>
 
M

murrayatuptowngallery

Thanks P-E and Dr.S.

I used to fight spammers when I had a 5-10% 'kill' rate (satisfaction
that someone's account had been closed or billed for cleanup). Now most
responses are (possibly legitimate) denials it's their users, just a
forged address.

I will experiment some more with Dr Stockton's version. For the time
being I just went back to screen display and that's pretty messy.

I DO spend some time referring to standards/references. Sometimes it
helps, sometimes it shows you how deep the water actually is.

Murray
 
D

Dr John Stockton

JRS: In article <[email protected]>,
dated Sat, 19 Nov 2005 10:50:30, seen in
murrayatuptowngallery said:
I DO spend some time referring to standards/references. Sometimes it
helps, sometimes it shows you how deep the water actually is.

In that case, perhaps you will refer to the newsgroup FAQ, to find out
how a news response should be formatted.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,835
Latest member
KetoRushACVBuy

Latest Threads

Top