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


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

help coding a hash table #2

Started byJRough <janis.rough@gmail.com>
First post2012-02-06 20:07 -0800
Last post2012-02-07 11:10 +0000
Articles 9 — 7 participants

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


Contents

  help coding a hash table #2 JRough <janis.rough@gmail.com> - 2012-02-06 20:07 -0800
    Re: help coding a hash table #2 "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-02-06 22:07 -0800
    Re: help coding a hash table #2 Bart Van der Donck <bart@nijlen.com> - 2012-02-07 02:24 -0800
      Re: help coding a hash table #2 Dr J R Stockton <reply1206@merlyn.demon.co.uk> - 2012-02-08 20:03 +0000
        Re: help coding a hash table #2 Bart Van der Donck <bart@nijlen.com> - 2012-02-09 02:57 -0800
      Re: help coding a hash table #2 JRough <janis.rough@gmail.com> - 2012-02-09 18:04 -0800
        Re: help coding a hash table #2 Jeff North <jnorthau@yahoo.com.au> - 2012-02-10 18:37 +1100
          Re: help coding a hash table #2 "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-02-10 09:16 +0000
    Re: help coding a hash table #2 John G Harris <john@nospam.demon.co.uk> - 2012-02-07 11:10 +0000

#11292 — help coding a hash table #2

FromJRough <janis.rough@gmail.com>
Date2012-02-06 20:07 -0800
Subjecthelp coding a hash table #2
Message-ID<d6cba95b-c744-428d-85c6-1e200eb0de6c@v6g2000pba.googlegroups.com>
This is the time array, with hour key value pair.
var time = new Array();
time['hour'][0] = "12:00";
time['hour'][1] = "13:00";
time['hour'][2] = "14:00";
time['hour'][3] = "15:00";
time['hour'][4] = "16:00";
time['hour'][5] = "17:00";
time['hour'][6] = "18:00";
time['hour'][7] = "19:00";
time['hour'][8] = "20:00";
time['hour'][9] = "21:00";
time['hour'][10] = "22:00";
time['hour'][11] = "23:00";
time['hour'][12] = "24:00";
time['hour'][13] = "1:00";
time['hour'][14] = "2:00";
time['hour'][15] = "3:00";
time['hour'][16] = "4:00";
time['hour'][17] = "5:00";
time['hour'][18] = "6:00";
time['hour'][19] = "7:00";
time['hour'][20] = "8:00";
time['hour'][21] = "9:00";
time['hour'][22] = "10:00";
time['hour'][23] = "11:00";
// show the values stored
for (var i in time[hour][i]) {
 {        }
}

I think there is another loop inside the for in   that adds the
minutes [00,01,02,03,04....60]
and also another one for the seconds?  If you could give me an
example.  I read the page on Hash TAbles and it isn't clear.
http://www.mojavelinux.com/articles/javascript_hashes.html
Thanks,

[toc] | [next] | [standalone]


#11429

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2012-02-06 22:07 -0800
Message-ID<f903e739-1af2-4138-8931-d909b5f20b21@i18g2000yqf.googlegroups.com>
In reply to#11292
On Feb 6, 10:07 pm, JRough <janis.ro...@gmail.com> wrote:
> This is the time array, with hour key value pair.
> var time = new Array();
> time['hour'][0] = "12:00";
> time['hour'][1] = "13:00";
> time['hour'][2] = "14:00";
> time['hour'][3] = "15:00";
> time['hour'][4] = "16:00";
> time['hour'][5] = "17:00";
> time['hour'][6] = "18:00";
> time['hour'][7] = "19:00";
> time['hour'][8] = "20:00";
> time['hour'][9] = "21:00";
> time['hour'][10] = "22:00";
> time['hour'][11] = "23:00";
> time['hour'][12] = "24:00";
> time['hour'][13] = "1:00";
> time['hour'][14] = "2:00";
> time['hour'][15] = "3:00";
> time['hour'][16] = "4:00";
> time['hour'][17] = "5:00";
> time['hour'][18] = "6:00";
> time['hour'][19] = "7:00";
> time['hour'][20] = "8:00";
> time['hour'][21] = "9:00";
> time['hour'][22] = "10:00";
> time['hour'][23] = "11:00";
> // show the values stored
> for (var i in time[hour][i]) {
>  {        }
>
> }
>
> I think there is another loop inside the for in   that adds the
> minutes [00,01,02,03,04....60]
> and also another one for the seconds?  If you could give me an
> example.  I read the page on Hash TAbles and it isn't clear.http://www.mojavelinux.com/articles/javascript_hashes.html
> Thanks,

What are you trying to do in the bigger picture? What is your goal? Is
this something you made to teach yourself or are you trying to
accomplish something else?

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


#11432

FromBart Van der Donck <bart@nijlen.com>
Date2012-02-07 02:24 -0800
Message-ID<efc2aeda-f605-40b2-979c-ed5972313e55@t24g2000yqj.googlegroups.com>
In reply to#11292
JRough wrote:

> This is the time array, with hour key value pair.
> var time = new Array();
> time['hour'][0] = "12:00";
> time['hour'][1] = "13:00";
> time['hour'][2] = "14:00";
> time['hour'][3] = "15:00";
> time['hour'][4] = "16:00";
> time['hour'][5] = "17:00";
> time['hour'][6] = "18:00";
> time['hour'][7] = "19:00";
> time['hour'][8] = "20:00";
> time['hour'][9] = "21:00";
> time['hour'][10] = "22:00";
> time['hour'][11] = "23:00";
> time['hour'][12] = "24:00";
> time['hour'][13] = "1:00";
> time['hour'][14] = "2:00";
> time['hour'][15] = "3:00";
> time['hour'][16] = "4:00";
> time['hour'][17] = "5:00";
> time['hour'][18] = "6:00";
> time['hour'][19] = "7:00";
> time['hour'][20] = "8:00";
> time['hour'][21] = "9:00";
> time['hour'][22] = "10:00";
> time['hour'][23] = "11:00";
> // show the values stored
> for (var i in time[hour][i]) {
>  {        }
>
> }
>
> I think there is another loop inside the for in   that adds the
> minutes [00,01,02,03,04....60]
> and also another one for the seconds?  If you could give me an
> example.  I read the page on Hash TAbles and it isn't clear.http://www.mojavelinux.com/articles/javascript_hashes.html

These assignments are invalid; first you declare 'time' as an Array,
but then you handle it as an Object with one key ('hour').

The correct initialization would be:

  var time = new Object();
  time.hour = new Array();

But it's better to not use the words 'time' and 'hour' in this
context.

The following code would give you hours, minutes, seconds:

  // hours
  for (var i=0; i<=23; ++i)  document.write(i+':00<br>');
  // minutes or seconds
  for (var i=0; i<=60; ++i)  document.write(i+':00<br>');

Looping through every second is not recommended, as you will end up
with 86,400 loops.

To store it in your data format:

  // init
  var t = new Object();
  t.h = new Array();
  t.m = new Array();
  t.s = new Array();

  // hours
  for (var i=0; i<=23; ++i)  {
    t.h[i] = i + ':00';
  }

  // minutes or seconds
  for (var i=0; i<=60; ++i)  {
    t.m[i] = i;
    t.s[i] = i;
  }

But I don't see why it's useful; because you then have t.h[11] =
'11:00', t.m[48] = 48, t.s[23] = 23, etc.

Hope this helps,

--
 Bart

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


#11508

FromDr J R Stockton <reply1206@merlyn.demon.co.uk>
Date2012-02-08 20:03 +0000
Message-ID<kNx2quJOUtMPFwz0@invalid.uk.co.demon.merlyn.invalid>
In reply to#11432
In comp.lang.javascript message <efc2aeda-f605-40b2-979c-ed5972313e55@t2
4g2000yqj.googlegroups.com>, Tue, 7 Feb 2012 02:24:34, Bart Van der
Donck <bart@nijlen.com> posted:

>
>Looping through every second is not recommended, as you will end up
>with 86,400 loops.

Is that a problem?  I have Zeller's 1886 algorithm for Gregorian Easter
Sunday, and can do a million values in 222 ms.  And I can push a million
numbers into an array in 106 ms.  Firefox 10, Win XP sp3, P4/3GHz.

-- 
 (c) John Stockton, nr London UK.  ?@merlyn.demon.co.uk  DOS 3.3 6.20 ; WinXP.
   Web  <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
   PAS EXE TXT ZIP via  <http://www.merlyn.demon.co.uk/programs/00index.htm>
   My DOS  <http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.

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


#11513

FromBart Van der Donck <bart@nijlen.com>
Date2012-02-09 02:57 -0800
Message-ID<a4b1d122-eba2-4af2-9eb4-868691b3bdd0@db5g2000vbb.googlegroups.com>
In reply to#11508
Dr J R Stockton wrote:

> In comp.lang.javascript message <efc2aeda-f605-40b2-979c-ed5972313e55@t2
> 4g2000yqj.googlegroups.com>, Tue, 7 Feb 2012 02:24:34, Bart Van der
> Donck <b...@nijlen.com> posted:
>
>> Looping through every second is not recommended, as you will end up
>> with 86,400 loops.
>
> Is that a problem?  I have Zeller's 1886 algorithm for Gregorian Easter
> Sunday, and can do a million values in 222 ms.  And I can push a million
> numbers into an array in 106 ms.  Firefox 10, Win XP sp3, P4/3GHz.

It depends what happens inside the loop. The problem occured only
while document.write-ing the results (00:00:00-23:59:59).

--
 Bart

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


#11531

FromJRough <janis.rough@gmail.com>
Date2012-02-09 18:04 -0800
Message-ID<79930e44-4870-4d76-93c1-874f13d8d8ec@sk8g2000pbc.googlegroups.com>
In reply to#11432
On Feb 7, 2:24 am, Bart Van der Donck <b...@nijlen.com> wrote:
> JRough wrote:
> > This is the time array, with hour key value pair.
> > var time = new Array();
> > time['hour'][0] = "12:00";
> > time['hour'][1] = "13:00";
> > time['hour'][2] = "14:00";
> > time['hour'][3] = "15:00";
> > time['hour'][4] = "16:00";
> > time['hour'][5] = "17:00";
> > time['hour'][6] = "18:00";
> > time['hour'][7] = "19:00";
> > time['hour'][8] = "20:00";
> > time['hour'][9] = "21:00";
> > time['hour'][10] = "22:00";
> > time['hour'][11] = "23:00";
> > time['hour'][12] = "24:00";
> > time['hour'][13] = "1:00";
> > time['hour'][14] = "2:00";
> > time['hour'][15] = "3:00";
> > time['hour'][16] = "4:00";
> > time['hour'][17] = "5:00";
> > time['hour'][18] = "6:00";
> > time['hour'][19] = "7:00";
> > time['hour'][20] = "8:00";
> > time['hour'][21] = "9:00";
> > time['hour'][22] = "10:00";
> > time['hour'][23] = "11:00";
> > // show the values stored
> > for (var i in time[hour][i]) {
> >  {        }
>
> > }
>
> > I think there is another loop inside the for in   that adds the
> > minutes [00,01,02,03,04....60]
> > and also another one for the seconds?  If you could give me an
> > example.  I read the page on Hash TAbles and it isn't clear.http://www.mojavelinux.com/articles/javascript_hashes.html
>
> These assignments are invalid; first you declare 'time' as an Array,
> but then you handle it as an Object with one key ('hour').
>
> The correct initialization would be:
>
>   var time = new Object();
>   time.hour = new Array();
>
> But it's better to not use the words 'time' and 'hour' in this
> context.
>
> The following code would give you hours, minutes, seconds:
>
>   // hours
>   for (var i=0; i<=23; ++i)  document.write(i+':00<br>');
>   // minutes or seconds
>   for (var i=0; i<=60; ++i)  document.write(i+':00<br>');
>
> Looping through every second is not recommended, as you will end up
> with 86,400 loops.
>
> To store it in your data format:
>
>   // init
>   var t = new Object();
>   t.h = new Array();
>   t.m = new Array();
>   t.s = new Array();
>
>   // hours
>   for (var i=0; i<=23; ++i)  {
>     t.h[i] = i + ':00';
>   }
>
>   // minutes or seconds
>   for (var i=0; i<=60; ++i)  {
>     t.m[i] = i;
>     t.s[i] = i;
>   }
>
> But I don't see why it's useful; because you then have t.h[11] =
> '11:00', t.m[48] = 48, t.s[23] = 23, etc.
>
> Hope this helps,
>
> --
>  Bart

Many thanks for all the replies and explaining how to initialize the
array.  What the bigger picture is I want a time picker to facilitate
user input of time [hours,minutes,seconds] something like YUI 3
timepicker.  http://stephenwoods.net/demos/timepicker/demo.html   I
want 3 related drop downs in a input field.  I want the user to select
the hour
with a click event.  Then that triggers another event that relates a
dropdown with the minutes.  They click the minutes and it triggers
another event to select the minutes.  So after thinking about it I
only need 1 array  from 1 to 60.  I can use that array 3 times.   Or
to make it easier I can use 2 arrays.  1 for hours and 1 for minutes
and seconds.  I need the loop for the front end, which I guess would
be your for loops tied to the 3 events.
http://stephenwoods.net/demos/timepicker/demo.html

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


#11535

FromJeff North <jnorthau@yahoo.com.au>
Date2012-02-10 18:37 +1100
Message-ID<ddh9j7l29vipikng2mrvvjhi2u6jppaual@4ax.com>
In reply to#11531
On Thu, 9 Feb 2012 18:04:40 -0800 (PST), in comp.lang.javascript
JRough <janis.rough@gmail.com>
<79930e44-4870-4d76-93c1-874f13d8d8ec@sk8g2000pbc.googlegroups.com>
wrote:

[snip]

>| 
>| Many thanks for all the replies and explaining how to initialize the
>| array.  What the bigger picture is I want a time picker to facilitate
>| user input of time [hours,minutes,seconds] something like YUI 3
>| timepicker.  http://stephenwoods.net/demos/timepicker/demo.html   I
>| want 3 related drop downs in a input field.  I want the user to select
>| the hour
>| with a click event.  Then that triggers another event that relates a
>| dropdown with the minutes.  They click the minutes and it triggers
>| another event to select the minutes.  So after thinking about it I
>| only need 1 array  from 1 to 60.  I can use that array 3 times.   Or
>| to make it easier I can use 2 arrays.  1 for hours and 1 for minutes
>| and seconds.  I need the loop for the front end, which I guess would
>| be your for loops tied to the 3 events.
>| http://stephenwoods.net/demos/timepicker/demo.html

Why complicate things? If you want select lists they already come with
events, namely the onChange event.
<select name=hrs><option>1</option><option>2</option> etc etc
<select name=mns><option>00</option><option>01</option> etc etc
<select name=sec><option>00</option><option>01</option> etc etc
<select name=ind><option>am</option><option>pm</option>

If you want to force the focus onto the next select list then you
would need to include:
<select name=hrs onChange="do your stuff here">

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


#11542

From"Evertjan." <exjxw.hannivoort@interxnl.net>
Date2012-02-10 09:16 +0000
Message-ID<Xns9FF56896CB948eejj99@194.109.133.133>
In reply to#11535
Jeff North wrote on 10 feb 2012 in comp.lang.javascript:

> <select name=hrs><option>1</option><option>2</option> etc etc
> <select name=mns><option>00</option><option>01</option> etc etc
> <select name=sec><option>00</option><option>01</option> etc etc
> <select name=ind><option>am</option><option>pm</option>

What about invisible radio input and labels:

<http://hannivoort.org/test/invisibleRadio.asp>

Sorry, 
quick and dirty, but very quick,
no am/pm-crap and no prevention of impossible numbers.




-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

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


#11433

FromJohn G Harris <john@nospam.demon.co.uk>
Date2012-02-07 11:10 +0000
Message-ID<tIqonNHjaQMPFwip@J.A830F0FF37FB96852AD08924D9443D28E23ED5CD>
In reply to#11292
On Mon, 6 Feb 2012 at 20:07:13, in comp.lang.javascript, JRough wrote:

  <snip>
>I read the page on Hash TAbles and it isn't clear.
>http://www.mojavelinux.com/articles/javascript_hashes.html

That article completely misunderstands arrays and objects. An Array
object is an ordinary object with the extra feature that its properties
can have numeric values, as in a[3], and a length property that is one
more than the highest numeric index in use.

If you want to store string:value couples use an ordinary object, as in
  var o = {};
  o.red = 5;
  o.blue= 9;
  o["white"] = 3;  /* alternative "array" notation */

And another thing, a 'hash' table is a particular kind of storage
structure; it is unlikely to be used to implement objects (an empty
object would grab a kB of ram or so).

  John
-- 
John Harris

[toc] | [prev] | [standalone]


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


csiph-web