Array - What am I doing wrong?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • M.Siler

    #1

    Array - What am I doing wrong?

    <HTML>
    <HEAD>
    <TITLE></TITLE>
    <SCRIPT>
    <!--

    var factor_val = new Array(8,7)

    factor_val[1,1] = 68.8
    factor_val[1,2] = 55
    factor_val[1,3] = 45.5
    factor_val[1,4] = 42.3
    factor_val[1,5] = 39.3
    factor_val[1,6] = 34.4
    factor_val[1,7] = 30.6
    factor_val[2,1] = 36.7
    factor_val[2,2] = 31
    factor_val[2,3] = 25.8
    factor_val[2,4] = 23.8
    factor_val[2,5] = 22.1
    factor_val[2,6] = 19.4
    factor_val[2,7] = 17.2
    factor_val[3,1] = 30.6
    factor_val[3,2] = 26.5
    factor_val[3,3] = 20.4
    factor_val[3,4] = 18.8
    factor_val[3,5] = 17.5
    factor_val[3,6] = 15.3
    factor_val[3,7] = 13.6
    factor_val[4,1] = 24.3
    factor_val[4,2] = 19.7
    factor_val[4,3] = 16.5
    factor_val[4,4] = 15.2
    factor_val[4,5] = 14.1
    factor_val[4,6] = 12.4
    factor_val[4,7] = 11
    factor_val[5,1] = 17.2
    factor_val[5,2] = 13.7
    factor_val[5,3] = 11.5
    factor_val[5,4] = 10.6
    factor_val[5,5] = 9.8
    factor_val[5,6] = 8.6
    factor_val[5,7] = 7.6
    factor_val[6,1] = 9.7
    factor_val[6,2] = 7.7
    factor_val[6,3] = 6.5
    factor_val[6,4] = 5.9
    factor_val[6,5] = 5.5
    factor_val[6,6] = 4.8
    factor_val[6,7] = 4.3
    factor_val[7,1] = 7.6
    factor_val[7,2] = 6
    factor_val[7,3] = 5.1
    factor_val[7,4] = 4.7
    factor_val[7,5] = 4.4
    factor_val[7,6] = 3.8
    factor_val[7,7] = 3.4
    factor_val[8,1] = 4
    factor_val[8,2] = 3
    factor_val[8,3] = 2.7
    factor_val[8,4] = 2.6
    factor_val[8,5] = 2.5
    factor_val[8,6] = 2
    factor_val[8,7] = 1.7

    function compute(form)
    {
    var myindex_x = form.diameter.s electedIndex;
    var myindex_y = form.depth.sele ctedIndex;

    if (myindex_x == 0)
    {
    alert("Select a Diameter.");
    }
    else if (myindex_y == 0)
    {
    alert("Select a Depth.");
    }
    else
    {
    form.x_val.valu e = myindex_x;
    form.y_val.valu e = myindex_y;
    form.f_val.valu e = factor_val[myindex_x, myindex_y];
    form.answer_val .value = form.num_of_hol es.value/factor_val[myindex_x,
    myindex_y];

    }
    }

    -->
    </SCRIPT>
    </HEAD>

    <BODY>

    <form>

    <p><input type="text" name="num_of_ho les" size="4" value="0"> Number of
    Holes</p>

    <p>
    <select name="diameter" >
    <option>Selec t the Diameter</option>
    <option>6</option>
    <option>8</option>
    <option>9</option>
    <option>10</option>
    <option>12</option>
    <option>16</option>
    <option>18</option>
    <option>24</option>
    </select>
    </p>

    <p>
    <select name="depth">
    <option>Selec t the Depth</option>
    <option>24</option>
    <option>30</option>
    <option>36</option>
    <option>39</option>
    <option>42</option>
    <option>48</option>
    <option>54</option>
    </select>
    </p>

    <p><font color="#0000FF" ><input type="text" name="x_val" size="4" value="0"
    onFocus='this.b lur()'> X</font></p>
    <p><font color="#0000FF" ><input type="text" name="y_val" size="4" value="0"
    onFocus='this.b lur()'> Y</font></p>
    <p><font color="#0000FF" ><input type="text" name="f_val" size="4" value="0"
    onFocus='this.b lur()'> Factor</font></p>
    <p><input type="text" name="answer_va l" size="6" value="0"
    onFocus='this.b lur()'> Answer</p>

    </p>
    <INPUT TYPE="BUTTON" VALUE="Calculat e" onClick="comput e(this.form)">< input
    type="reset" value="Reset" name="B2">
    </form>
    </BODY>
    </HTML>


  • Evertjan.

    #2
    Re: Array - What am I doing wrong?

    M.Siler wrote on 16 nov 2003 in comp.lang.javas cript:
    [color=blue]
    > var factor_val = new Array(8,7)
    >[/color]

    There are no cats in America,
    I mean there are no multidimensiona l arrays in Javascript.


    <script>

    var factor_val = new Array(8,7)

    alert(factor_va l[0]) // shows 8
    alert(factor_va l[1]) // shows 7

    </script>

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

    Comment

    • Juliette

      #3
      Re: Array - What am I doing wrong?

      "Evertjan." wrote:[color=blue]
      >
      > M.Siler wrote on 16 nov 2003 in comp.lang.javas cript:
      >[color=green]
      > > var factor_val = new Array(8,7)
      > >[/color]
      >
      > There are no cats in America,
      > I mean there are no multidimensiona l arrays in Javascript.
      >
      > <script>
      >
      > var factor_val = new Array(8,7)
      >
      > alert(factor_va l[0]) // shows 8
      > alert(factor_va l[1]) // shows 7
      >
      > </script>
      >
      > --
      > Evertjan.
      > The Netherlands.
      > (Please change the x'es to dots in my emailaddress)[/color]


      I don't agree and the NS javascript specs agree with me: there are
      multidimensiona l arrays in Javascript, except you have to define them
      slightly differently from what has been done in the sample code.

      The following comes straight from the Client-Side Javascript Reference
      (v 1.3):

      ** START QUOTE **

      Example 2: Two-dimensional array. The following code creates a
      two-dimensional array and assigns the results to myVar.

      myVar="Multidim ensional array test; "
      a = new Array(4)
      for (i=0; i < 4; i++) {
      a[i] = new Array(4)
      for (j=0; j < 4; j++) {
      a[i][j] = "["+i+","+j+"]"
      }
      }
      for (i=0; i < 4; i++) {
      str = "Row "+i+":"
      for (j=0; j < 4; j++) {
      str += a[i][j]
      }
      myVar += str +"; "
      }

      This example assigns the following string to myVar (line breaks are used
      here for readability):

      Multidimensiona l array test;
      Row 0:[0,0][0,1][0,2][0,3];
      Row 1:[1,0][1,1][1,2][1,3];
      Row 2:[2,0][2,1][2,2][2,3];
      Row 3:[3,0][3,1][3,2][3,3];

      ** END OF QUOTE **


      So to answer Mr Siler's question:
      You have to define your array using the following method:
      ** Please take note: normal array assignments start at 0 (not at 1), so
      the first argument should be refered to as factor_val[0][0] NOT
      factor_val[1][1] and definitely NOT factor_val[1,0].

      var factor_val = new Array();
      factor_val[0] = new Array();
      factor_val[0][0] = 68.8;
      factor_val[0][1] = 55;
      factor_val[0][2] = 45.5;
      factor_val[0][3] = 42.3;
      etc...
      factor_val[1] = new Array();
      factor_val[1][0] = 36.7;
      factor_val[1][1] = 31;
      etc...
      etc...

      I presume you get my drift.

      Good luck,
      Juliette

      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: Array - What am I doing wrong?

        Juliette <"jrf[spamblock]"@jokeaday. net> writes:
        [color=blue]
        > "Evertjan." wrote:[color=green]
        >>
        >> M.Siler wrote on 16 nov 2003 in comp.lang.javas cript:
        >>[color=darkred]
        >> > var factor_val = new Array(8,7)
        >> >[/color]
        >>
        >> There are no cats in America,
        >> I mean there are no multidimensiona l arrays in Javascript.
        >>
        >> <script>
        >>
        >> var factor_val = new Array(8,7)
        >>
        >> alert(factor_va l[0]) // shows 8
        >> alert(factor_va l[1]) // shows 7
        >>
        >> </script>
        >>
        >> --
        >> Evertjan.
        >> The Netherlands.
        >> (Please change the x'es to dots in my emailaddress)[/color]
        >
        >
        > I don't agree and the NS javascript specs agree with me: there are
        > multidimensiona l arrays in Javascript, except you have to define them
        > slightly differently from what has been done in the sample code.[/color]

        I disagree with you. There are no multidimensiona l arrays in
        Javascript. There is no single array that is multidimensiona l. What
        you do have is arrays containing arrays, which is a completely
        different thing (although it can be used to emulate multidimensiona l
        arrays in their absence).

        C has multidimensiona l arrays. Java doesn't, it only has arrays of
        arrays.

        This is ofcourse splitting hairs, i.e., purely a matter of
        terminology ...
        [color=blue]
        > The following comes straight from the Client-Side Javascript Reference
        > (v 1.3):
        >
        > ** START QUOTE **
        >
        > Example 2: Two-dimensional array. The following code creates a
        > two-dimensional array and assigns the results to myVar.[/color]

        .... and I disagree with their use of terminology.

        [color=blue]
        > So to answer Mr Siler's question:
        > You have to define your array using the following method:[/color]

        .... a perfectly good advice.
        [color=blue]
        > var factor_val = new Array();
        > factor_val[0] = new Array();
        > factor_val[0][0] = 68.8;
        > factor_val[0][1] = 55;
        > factor_val[0][2] = 45.5;
        > factor_val[0][3] = 42.3;
        > etc...
        > factor_val[1] = new Array();
        > factor_val[1][0] = 36.7;
        > factor_val[1][1] = 31;
        > etc...[/color]

        You can also use array literals:
        var factor_val = [[68.8, 55, 45.5, 42.3, 39.3, 34.4, 30.6],
        [36.7, 31, ... ],
        ...
        [..., 2.6, 2.5, 2, 1.7]
        ];

        /L
        --
        Lasse Reichstein Nielsen - lrn@hotpop.com
        DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        • Traveler

          #5
          Re: Array - What am I doing wrong?

          I have been able to set up arrays as follows:

          MyArray = [[1,2,3],[4,5,6],[7,8,9]]

          MyArray[1][1]=5
          etc.



          In article <3FB7B268.22570 E47@jokeaday.ne t>, Juliette
          <"jrf[spamblock]"@jokeaday. net> wrote:
          [color=blue]
          > "Evertjan." wrote:[color=green]
          > >
          > > M.Siler wrote on 16 nov 2003 in comp.lang.javas cript:
          > >[color=darkred]
          > > > var factor_val = new Array(8,7)
          > > >[/color]
          > >
          > > There are no cats in America,
          > > I mean there are no multidimensiona l arrays in Javascript.
          > >
          > > <script>
          > >
          > > var factor_val = new Array(8,7)
          > >
          > > alert(factor_va l[0]) // shows 8
          > > alert(factor_va l[1]) // shows 7
          > >
          > > </script>
          > >
          > > --
          > > Evertjan.
          > > The Netherlands.
          > > (Please change the x'es to dots in my emailaddress)[/color]
          >
          >
          > I don't agree and the NS javascript specs agree with me: there are
          > multidimensiona l arrays in Javascript, except you have to define them
          > slightly differently from what has been done in the sample code.
          >
          > The following comes straight from the Client-Side Javascript Reference
          > (v 1.3):
          >
          > ** START QUOTE **
          >
          > Example 2: Two-dimensional array. The following code creates a
          > two-dimensional array and assigns the results to myVar.
          >
          > myVar="Multidim ensional array test; "
          > a = new Array(4)
          > for (i=0; i < 4; i++) {
          > a[i] = new Array(4)
          > for (j=0; j < 4; j++) {
          > a[i][j] = "["+i+","+j+"]"
          > }
          > }
          > for (i=0; i < 4; i++) {
          > str = "Row "+i+":"
          > for (j=0; j < 4; j++) {
          > str += a[i][j]
          > }
          > myVar += str +"; "
          > }
          >
          > This example assigns the following string to myVar (line breaks are used
          > here for readability):
          >
          > Multidimensiona l array test;
          > Row 0:[0,0][0,1][0,2][0,3];
          > Row 1:[1,0][1,1][1,2][1,3];
          > Row 2:[2,0][2,1][2,2][2,3];
          > Row 3:[3,0][3,1][3,2][3,3];
          >
          > ** END OF QUOTE **
          >
          >
          > So to answer Mr Siler's question:
          > You have to define your array using the following method:
          > ** Please take note: normal array assignments start at 0 (not at 1), so
          > the first argument should be refered to as factor_val[0][0] NOT
          > factor_val[1][1] and definitely NOT factor_val[1,0].
          >
          > var factor_val = new Array();
          > factor_val[0] = new Array();
          > factor_val[0][0] = 68.8;
          > factor_val[0][1] = 55;
          > factor_val[0][2] = 45.5;
          > factor_val[0][3] = 42.3;
          > etc...
          > factor_val[1] = new Array();
          > factor_val[1][0] = 36.7;
          > factor_val[1][1] = 31;
          > etc...
          > etc...
          >
          > I presume you get my drift.
          >
          > Good luck,
          > Juliette[/color]


          -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
          http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
          -----== Over 100,000 Newsgroups - 19 Different Servers! =-----

          Comment

          • Juliette

            #6
            Re: Array - What am I doing wrong?

            Lasse Reichstein Nielsen wrote:[color=blue]
            >
            > Juliette <"jrf[spamblock]"@jokeaday. net> writes:
            >[color=green]
            > > "Evertjan." wrote:[color=darkred]
            > >>
            > >> M.Siler wrote on 16 nov 2003 in comp.lang.javas cript:
            > >>
            > >> > var factor_val = new Array(8,7)
            > >> >
            > >>
            > >> There are no cats in America,
            > >> I mean there are no multidimensiona l arrays in Javascript.
            > >>
            > >> <script>
            > >>
            > >> var factor_val = new Array(8,7)
            > >>
            > >> alert(factor_va l[0]) // shows 8
            > >> alert(factor_va l[1]) // shows 7
            > >>
            > >> </script>
            > >>
            > >> --
            > >> Evertjan.
            > >> The Netherlands.
            > >> (Please change the x'es to dots in my emailaddress)[/color]
            > >
            > >
            > > I don't agree and the NS javascript specs agree with me: there are
            > > multidimensiona l arrays in Javascript, except you have to define them
            > > slightly differently from what has been done in the sample code.[/color]
            >
            > I disagree with you. There are no multidimensiona l arrays in
            > Javascript. There is no single array that is multidimensiona l. What
            > you do have is arrays containing arrays, which is a completely
            > different thing (although it can be used to emulate multidimensiona l
            > arrays in their absence).
            >
            > C has multidimensiona l arrays. Java doesn't, it only has arrays of
            > arrays.
            >
            > This is ofcourse splitting hairs, i.e., purely a matter of
            > terminology ...
            >[color=green]
            > > The following comes straight from the Client-Side Javascript Reference
            > > (v 1.3):
            > >
            > > ** START QUOTE **
            > >
            > > Example 2: Two-dimensional array. The following code creates a
            > > two-dimensional array and assigns the results to myVar.[/color]
            >
            > ... and I disagree with their use of terminology.
            >[color=green]
            > > So to answer Mr Siler's question:
            > > You have to define your array using the following method:[/color]
            >
            > ... a perfectly good advice.
            >[color=green]
            > > var factor_val = new Array();
            > > factor_val[0] = new Array();
            > > factor_val[0][0] = 68.8;
            > > factor_val[0][1] = 55;
            > > factor_val[0][2] = 45.5;
            > > factor_val[0][3] = 42.3;
            > > etc...
            > > factor_val[1] = new Array();
            > > factor_val[1][0] = 36.7;
            > > factor_val[1][1] = 31;
            > > etc...[/color]
            >
            > You can also use array literals:
            > var factor_val = [[68.8, 55, 45.5, 42.3, 39.3, 34.4, 30.6],
            > [36.7, 31, ... ],
            > ...
            > [..., 2.6, 2.5, 2, 1.7]
            > ];
            >
            > /L
            > --
            > Lasse Reichstein Nielsen - lrn@hotpop.com
            > DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
            > 'Faith without judgement merely degrades the spirit divine.'[/color]


            Lasse,

            Of course you are completely correct concerning the terminology, but at
            the end of the day the effect is what counts and as desired.

            The shorthand array definition which you show is absolutely correct and
            much more efficient.
            The longhand version just goes to show what is actually being done ;-).

            Greetz, Juliette

            Comment

            • M.Siler

              #7
              Re: Array - What am I doing wrong?

              Thanks for everyone help... I agree it's not a true multidimensiona l array,
              but it works close enough like one... here's what I ended up with.

              -----------------
              <HTML>
              <HEAD>
              <TITLE></TITLE>
              <SCRIPT>
              <!--

              var row_1 = new Array(68.8, 36.7, 30.6, 24.3, 17.2, 9.7, 7.6, 4)
              var row_2 = new Array(55, 31, 26.5, 19.7, 13.7, 7.7, 6, 3)
              var row_3 = new Array(45.5, 25.8, 20.4, 16.5, 11.5, 6.5, 5.1, 2.7)
              var row_4 = new Array(42.3, 23.8, 18.8, 15.2, 10.6, 5.9, 4.7, 2.6)
              var row_5 = new Array(39.3, 22.1, 17.5, 14.1, 9.8, 5.5, 4.4, 2.5)
              var row_6 = new Array(34.4, 19.4, 15.3, 12.4, 8.6, 4.8, 3.8, 2)
              var row_7 = new Array(30.6, 17.2, 13.6, 11, 7.6, 4.3, 3.4, 1.7)

              var M = new Array(row_1, row_2, row_3, row_4, row_5, row_6, row_7)

              function compute(form)
              {
              var myindex_x = form.diameter.s electedIndex;
              var myindex_y = form.depth.sele ctedIndex;

              if (myindex_x == 0)
              {
              alert("Select a Diameter.");
              }
              else if (myindex_y == 0)
              {
              alert("Select a Depth.");
              }
              else
              {
              form.f_val.valu e = M[myindex_y-1][myindex_x-1];
              form.answer_val .value =
              form.num_of_hol es.value/M[myindex_y-1][myindex_x-1];
              }
              }

              -->
              </SCRIPT>
              </HEAD>

              <BODY>

              <form>

              <p><input type="text" name="num_of_ho les" size="4" value="0"> Number of
              Holes</p>

              <p>
              <select name="diameter" >
              <option>Selec t the</option>
              <option>6</option>
              <option>8</option>
              <option>9</option>
              <option>10</option>
              <option>12</option>
              <option>16</option>
              <option>18</option>
              <option>24</option>
              </select> Diameter</p>

              <p>
              <select name="depth">
              <option>Selec t the</option>
              <option>24</option>
              <option>30</option>
              <option>36</option>
              <option>39</option>
              <option>42</option>
              <option>48</option>
              <option>54</option>
              </select> Depth</p>

              <p><font color="#0000FF" ><input type="text" name="f_val" size="4" value="0"
              onFocus='this.b lur()'> Factor</font></p>
              <p><input type="text" name="answer_va l" size="6" value="0"
              onFocus='this.b lur()'> Answer</p>

              </p>
              <INPUT TYPE="BUTTON" VALUE="Calculat e" onClick="comput e(this.form)">< input
              type="reset" value="Reset" name="B2">
              </form>
              </BODY>
              </HTML>

              -----------------

              Thanks again!


              "Juliette" <"jrf[spamblock]"@jokeaday. net> wrote in message
              news:3FB7BC9D.D 7327242@jokeada y.net...[color=blue]
              > Lasse Reichstein Nielsen wrote:[color=green]
              > >
              > > Juliette <"jrf[spamblock]"@jokeaday. net> writes:
              > >[color=darkred]
              > > > "Evertjan." wrote:
              > > >>
              > > >> M.Siler wrote on 16 nov 2003 in comp.lang.javas cript:
              > > >>
              > > >> > var factor_val = new Array(8,7)
              > > >> >
              > > >>
              > > >> There are no cats in America,
              > > >> I mean there are no multidimensiona l arrays in Javascript.
              > > >>
              > > >> <script>
              > > >>
              > > >> var factor_val = new Array(8,7)
              > > >>
              > > >> alert(factor_va l[0]) // shows 8
              > > >> alert(factor_va l[1]) // shows 7
              > > >>
              > > >> </script>
              > > >>
              > > >> --
              > > >> Evertjan.
              > > >> The Netherlands.
              > > >> (Please change the x'es to dots in my emailaddress)
              > > >
              > > >
              > > > I don't agree and the NS javascript specs agree with me: there are
              > > > multidimensiona l arrays in Javascript, except you have to define them
              > > > slightly differently from what has been done in the sample code.[/color]
              > >
              > > I disagree with you. There are no multidimensiona l arrays in
              > > Javascript. There is no single array that is multidimensiona l. What
              > > you do have is arrays containing arrays, which is a completely
              > > different thing (although it can be used to emulate multidimensiona l
              > > arrays in their absence).
              > >
              > > C has multidimensiona l arrays. Java doesn't, it only has arrays of
              > > arrays.
              > >
              > > This is ofcourse splitting hairs, i.e., purely a matter of
              > > terminology ...
              > >[color=darkred]
              > > > The following comes straight from the Client-Side Javascript Reference
              > > > (v 1.3):
              > > >
              > > > ** START QUOTE **
              > > >
              > > > Example 2: Two-dimensional array. The following code creates a
              > > > two-dimensional array and assigns the results to myVar.[/color]
              > >
              > > ... and I disagree with their use of terminology.
              > >[color=darkred]
              > > > So to answer Mr Siler's question:
              > > > You have to define your array using the following method:[/color]
              > >
              > > ... a perfectly good advice.
              > >[color=darkred]
              > > > var factor_val = new Array();
              > > > factor_val[0] = new Array();
              > > > factor_val[0][0] = 68.8;
              > > > factor_val[0][1] = 55;
              > > > factor_val[0][2] = 45.5;
              > > > factor_val[0][3] = 42.3;
              > > > etc...
              > > > factor_val[1] = new Array();
              > > > factor_val[1][0] = 36.7;
              > > > factor_val[1][1] = 31;
              > > > etc...[/color]
              > >
              > > You can also use array literals:
              > > var factor_val = [[68.8, 55, 45.5, 42.3, 39.3, 34.4, 30.6],
              > > [36.7, 31, ... ],
              > > ...
              > > [..., 2.6, 2.5, 2, 1.7]
              > > ];
              > >
              > > /L
              > > --
              > > Lasse Reichstein Nielsen - lrn@hotpop.com
              > > DHTML Death Colors:[/color][/color]
              <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>[color=blue][color=green]
              > > 'Faith without judgement merely degrades the spirit divine.'[/color]
              >
              >
              > Lasse,
              >
              > Of course you are completely correct concerning the terminology, but at
              > the end of the day the effect is what counts and as desired.
              >
              > The shorthand array definition which you show is absolutely correct and
              > much more efficient.
              > The longhand version just goes to show what is actually being done ;-).
              >
              > Greetz, Juliette
              >[/color]


              Comment

              • Thomas 'PointedEars' Lahn

                #8
                Re: Array - What am I doing wrong?

                M.Siler wrote:
                [color=blue]
                > <HTML>[/color]

                The DOCTYPE declaration is missing for valid HTML.
                [color=blue]
                > <HEAD>[/color]

                The character set declaration with the `meta' element is missing for valid HTML.
                [color=blue]
                > <TITLE></TITLE>[/color]

                I do hope this is only a test case since `title' is "the most important
                element of an HTML document." (according to the W3C Style Guide.)
                [color=blue]
                > <SCRIPT>[/color]

                The type attribute is missing for valid HTML 4:

                <script type="text/javascript">
                [color=blue]
                > [...]
                > var row_1 = new Array(68.8, 36.7, 30.6, 24.3, 17.2, 9.7, 7.6, 4)
                > var row_2 = new Array(55, 31, 26.5, 19.7, 13.7, 7.7, 6, 3)
                > var row_3 = new Array(45.5, 25.8, 20.4, 16.5, 11.5, 6.5, 5.1, 2.7)
                > var row_4 = new Array(42.3, 23.8, 18.8, 15.2, 10.6, 5.9, 4.7, 2.6)
                > var row_5 = new Array(39.3, 22.1, 17.5, 14.1, 9.8, 5.5, 4.4, 2.5)
                > var row_6 = new Array(34.4, 19.4, 15.3, 12.4, 8.6, 4.8, 3.8, 2)
                > var row_7 = new Array(30.6, 17.2, 13.6, 11, 7.6, 4.3, 3.4, 1.7)
                >
                > var M = new Array(row_1, row_2, row_3, row_4, row_5, row_6, row_7)[/color]

                You are wasting memory and polluting the namespace by defining too many
                (global) variables. Except of the identifier for the last variable, which
                I recommend to start lower-cased and be more descriptive, the following is
                equal to the above:

                var matrix = new Array(
                new Array(68.8, 36.7, 30.6, 24.3, 17.2, 9.7, 7.6, 4),
                new Array(55, 31, 26.5, 19.7, 13.7, 7.7, 6, 3),
                new Array(45.5, 25.8, 20.4, 16.5, 11.5, 6.5, 5.1, 2.7),
                new Array(42.3, 23.8, 18.8, 15.2, 10.6, 5.9, 4.7, 2.6),
                new Array(39.3, 22.1, 17.5, 14.1, 9.8, 5.5, 4.4, 2.5),
                new Array(34.4, 19.4, 15.3, 12.4, 8.6, 4.8, 3.8, 2),
                new Array(30.6, 17.2, 13.6, 11, 7.6, 4.3, 3.4, 1.7));

                Or using Array literals:

                var matrix = [
                [68.8, 36.7, 30.6, 24.3, 17.2, 9.7, 7.6, 4],
                [55, 31, 26.5, 19.7, 13.7, 7.7, 6, 3],
                [45.5, 25.8, 20.4, 16.5, 11.5, 6.5, 5.1, 2.7],
                [42.3, 23.8, 18.8, 15.2, 10.6, 5.9, 4.7, 2.6],
                [39.3, 22.1, 17.5, 14.1, 9.8, 5.5, 4.4, 2.5],
                [34.4, 19.4, 15.3, 12.4, 8.6, 4.8, 3.8, 2],
                [30.6, 17.2, 13.6, 11, 7.6, 4.3, 3.4, 1.7]];

                AFAIS the latter (Array literals having Array literals als
                list elements) is not specified in ECMAScript Ed. 3 (CMIIW).


                PointedEars

                Comment

                • Lasse Reichstein Nielsen

                  #9
                  Re: Array - What am I doing wrong?

                  Thomas 'PointedEars' Lahn <PointedEars@we b.de> writes:
                  [color=blue]
                  > M.Siler wrote:
                  >[color=green]
                  >> <HTML>[/color]
                  >
                  > The DOCTYPE declaration is missing for valid HTML.[/color]

                  HTML 4, that is.
                  [color=blue][color=green]
                  >> <HEAD>[/color]
                  >
                  > The character set declaration with the `meta' element is missing for valid HTML.[/color]

                  The <meta http-equiv="Content-Type" ... > element is not required by
                  the HTML specification. The content-type can (should?) be supplied by
                  the server, that is what "http-equiv" means.
                  [color=blue]
                  > var matrix = [
                  > [68.8, 36.7, 30.6, 24.3, 17.2, 9.7, 7.6, 4],
                  > [55, 31, 26.5, 19.7, 13.7, 7.7, 6, 3],
                  > [45.5, 25.8, 20.4, 16.5, 11.5, 6.5, 5.1, 2.7],
                  > [42.3, 23.8, 18.8, 15.2, 10.6, 5.9, 4.7, 2.6],
                  > [39.3, 22.1, 17.5, 14.1, 9.8, 5.5, 4.4, 2.5],
                  > [34.4, 19.4, 15.3, 12.4, 8.6, 4.8, 3.8, 2],
                  > [30.6, 17.2, 13.6, 11, 7.6, 4.3, 3.4, 1.7]];
                  >
                  > AFAIS the latter (Array literals having Array literals als
                  > list elements) is not specified in ECMAScript Ed. 3 (CMIIW).[/color]

                  YAW. (Shouldn't that be "CMIIAW", or are you abbreviating a
                  contraction?)

                  The relevant grammar productions are:

                  ArrayLiteral : [ ElementList ]
                  ElementList : ElementList , Elison_opt AssignmentExpre ssion
                  AssignmentExpre ssion : ConditionalExpr ession
                  ConditionalExpr ession : LogicalORExpres sion
                  LogicalORExpres sion : LogicalANDExpre ssion
                  LogicalANDExpre ssion : BitwiseORExpres sion
                  BitwiseORExpres sion : BitwiseXORExpre ssion
                  BitwiseXORExpre ssion : BitwiseANDExpre ssion
                  BitwiseANDExpre ssion : EqualityExpress ion
                  EqualityExpress ion : RelationalExpre ssion
                  RelationalExpre ssion : ShiftExpression
                  ShiftExpression : AdditiveExpress ion
                  AdditiveExpress ion : MultiplicativeE xpression
                  MultiplicativeE xpression : UnaryExpression
                  UnaryExpression : PostfixExpressi on
                  PostfixExpressi on : LeftHandSideExp ression
                  LeftHandSideExp ression : NewExpression
                  NewExpression : MemberExpressio n
                  MemberExpressio n : PrimaryExpressi on
                  PrimaryExpressi on : ArrayLiteral

                  Enjoy :)
                  /L
                  --
                  Lasse Reichstein Nielsen - lrn@hotpop.com
                  DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
                  'Faith without judgement merely degrades the spirit divine.'

                  Comment

                  • HikksNotAtHome

                    #10
                    Re: Array - What am I doing wrong?

                    In article <d6bpmj3f.fsf@h otpop.com>, Lasse Reichstein Nielsen <lrn@hotpop.com >
                    writes:
                    [color=blue]
                    >YAW. (Shouldn't that be "CMIIAW", or are you abbreviating a
                    >contraction? )[/color]

                    WTFDYJS?

                    What the F*** did you just say? There are things to be said for abbreviations
                    when they may not be known to potential readers (I got the YAW, not the other
                    two)
                    --
                    Randy

                    Comment

                    • Lasse Reichstein Nielsen

                      #11
                      Re: Array - What am I doing wrong?

                      hikksnotathome@ aol.com (HikksNotAtHome ) writes:
                      [color=blue]
                      > In article <d6bpmj3f.fsf@h otpop.com>, Lasse Reichstein Nielsen <lrn@hotpop.com >
                      > writes:
                      >[color=green]
                      >>YAW. (Shouldn't that be "CMIIAW", or are you abbreviating a
                      >>contraction ?)[/color]
                      >
                      > WTFDYJS?
                      >
                      > What the F*** did you just say? There are things to be said for abbreviations
                      > when they may not be known to potential readers (I got the YAW, not the other
                      > two)[/color]

                      Ah, the person I responded to finished with "CMIIW", which I decoded as
                      "correct me if I'm wrong". The answer was ofcourse "YAW" (You are wrong).

                      If forced to do it, I would abbreviate "correct me if I'm wrong" as
                      CMIIAW, because I don't like to abbreviate a contraction.

                      Otherwise, I fully agree and normally try to avoid abbreviations, since
                      I don't understand all of them either (as a non-native English speaker)

                      /L
                      --
                      Lasse Reichstein Nielsen - lrn@hotpop.com
                      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
                      'Faith without judgement merely degrades the spirit divine.'

                      Comment

                      • Thomas 'PointedEars' Lahn

                        #12
                        Re: Array - What am I doing wrong?

                        Lasse Reichstein Nielsen wrote:
                        [color=blue]
                        > Thomas 'PointedEars' Lahn <PointedEars@we b.de> writes:[color=green]
                        >> M.Siler wrote:[color=darkred]
                        >>> <HTML>[/color]
                        >>
                        >> The DOCTYPE declaration is missing for valid HTML.[/color]
                        >
                        > HTML 4, that is.[/color]

                        It is required for *any* (valid) HTML:

                        http://www.w3.org/TR/html4/struct/global.html#h-7.2
                        [color=blue][color=green][color=darkred]
                        >>> <HEAD>[/color]
                        >>
                        >> The character set declaration with the `meta' element is missing for valid HTML.[/color]
                        >
                        > The <meta http-equiv="Content-Type" ... > element is not required by
                        > the HTML specification. The content-type can (should?) be supplied by
                        > the server, that is what "http-equiv" means.[/color]

                        http://www.w3.org/TR/html4/charset.html#doc-char-set

                        Validate a local document and you see it is required. It is, because HTML
                        is not required to be served via HTTP. You are right, the (HTTP) server
                        should supply the Content-Type along with the character set but if it does
                        not, the character set of the document differs from the server default (and
                        the author has no appropriate means to change that for the document) or if
                        there is no server, a user agent is required to obey the above declaration.
                        (XHTML is a different thing, of course, the `meta' element comes too late
                        for the XML parser, it requires the charset declaration within the XML
                        declaration before the DOCTYPE declaration.)
                        [color=blue][color=green]
                        >> AFAIS the latter (Array literals having Array literals als
                        >> list elements) is not specified in ECMAScript Ed. 3 (CMIIW).[/color]
                        >
                        > YAW.[/color]

                        I like that one :-) and I stand corrected.
                        [color=blue]
                        > (Shouldn't that be "CMIIAW",[/color]

                        No.
                        [color=blue]
                        > or are you abbreviating a contraction?)[/color]

                        Yes, and that is Usenet jargon. You may refer to the Jargon File or similar
                        dictionaries.
                        [color=blue]
                        > The relevant grammar productions are:
                        > [...]
                        >
                        > Enjoy :)[/color]

                        Thank you very much for your research. Using the same productions for the
                        most part[1], I could finally prove that object literals may also be nested
                        in themselves according to the specification(, a fact that has been denied
                        by somebody else (and I had not the energy to prove him wrong in those
                        days)). :)


                        \V/ Live long and prosper

                        PointedEars
                        ___________
                        [1] ObjectLiteral : { PropertyNameAnd ValueList }
                        PropertyNameAnd ValueList : AssignmentExpre ssion
                        ...
                        PrimaryExpressi on : ObjectLiteral

                        Comment

                        • Lasse Reichstein Nielsen

                          #13
                          Re: Array - What am I doing wrong?

                          Thomas 'PointedEars' Lahn <PointedEars@we b.de> writes:

                          [<!DOCTYPE> declaration][color=blue]
                          > It is required for *any* (valid) HTML:[/color]

                          Correct, my mistake.
                          [color=blue]
                          > http://www.w3.org/TR/html4/charset.html#doc-char-set[/color]

                          ---
                          To address server or configuration limitations, HTML documents may
                          include explicit information about the document's character encoding;
                          the META element can be used to provide user agents with this
                          information.
                          ---
                          [color=blue]
                          > Validate a local document and you see it is required.[/color]

                          Not if I tell the validator which character set to use.
                          It's a good idea to include the character encoding in the document,
                          but it is not required.
                          [color=blue]
                          > Thank you very much for your research. Using the same productions for the
                          > most part[1], I could finally prove that object literals may also be nested
                          > in themselves according to the specification(, a fact that has been denied
                          > by somebody else (and I had not the energy to prove him wrong in those
                          > days)). :)[/color]

                          It would me very bad design otherwise, if literal compound values could
                          not be nested, but could be embedded later.


                          I hope you can prove me mistaken on this one: Function declarations
                          are only allowed at the top level of programs or function bodies.
                          That means that

                          if (true) {
                          function foo(){}
                          }

                          is syntactically incorrect ECMAScript (it can't be an
                          ExpressionState ment containing a FunctionExpress ion, since
                          ExpressionState ments cannot start with "function") , and it
                          can't be a FunctionDeclara tion.

                          Browsers treat the above as a function declaration.
                          [color=blue]
                          > \V/ Live long and prosper[/color]

                          \V/ \V/ - I am not a nerd!


                          -L
                          --
                          Lasse Reichstein Nielsen - lrn@hotpop.com
                          DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
                          'Faith without judgement merely degrades the spirit divine.'

                          Comment

                          • John G Harris

                            #14
                            Re: Array - What am I doing wrong?

                            In article <ad6qzxld.fsf@h otpop.com>, Lasse Reichstein Nielsen
                            <lrn@hotpop.com > writes
                            <snip>[color=blue]
                            >I hope you can prove me mistaken on this one: Function declarations
                            >are only allowed at the top level of programs or function bodies.
                            >That means that
                            >
                            > if (true) {
                            > function foo(){}
                            > }
                            >
                            >is syntactically incorrect ECMAScript (it can't be an
                            >ExpressionStat ement containing a FunctionExpress ion, since
                            >ExpressionStat ements cannot start with "function") , and it
                            >can't be a FunctionDeclara tion.
                            >
                            >Browsers treat the above as a function declaration.[/color]

                            Think sneaky! This ...

                            <SCRIPT type="text/javascript">

                            if (2 == 2)
                            {
                            document.write( "True ");
                            var f = function () { document.write( "Wow!"); };
                            }
                            else
                            document.write( "False ");

                            f();

                            </SCRIPT>

                            .... is legal, and does what you were afraid of.

                            John
                            --
                            John Harris

                            Comment

                            • Douglas Crockford

                              #15
                              Re: Array - What am I doing wrong?

                              > >I hope you can prove me mistaken on this one: Function declarations[color=blue][color=green]
                              > >are only allowed at the top level of programs or function bodies.[/color][/color]

                              Whoa. Hold the phone. That is not true. Function statements can appear anywhere
                              that a statement can appear. And function expressions can appear pretty much
                              anywhere.
                              [color=blue][color=green]
                              > >That means that
                              > >
                              > > if (true) {
                              > > function foo(){}
                              > > }
                              > >
                              > >is syntactically incorrect ECMAScript (it can't be an
                              > >ExpressionStat ement containing a FunctionExpress ion, since
                              > >ExpressionStat ements cannot start with "function") , and it
                              > >can't be a FunctionDeclara tion.[/color][/color]

                              It is syntactically correct. Not only that,

                              (function (){ })();

                              is correct, too.
                              [color=blue]
                              > Think sneaky! This ...[/color]

                              There is no need to be sneaky when there are correct alternatives.


                              Comment

                              Working...