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


Groups > comp.lang.javascript > #22456

Re: Compressing js file?

From emf <emfril@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: Compressing js file?
Date 2013-12-28 15:12 -0500
Organization Aioe.org NNTP Server
Message-ID <l9nc1b$18c$1@speranza.aioe.org> (permalink)
References (2 earlier) <l9iq8h$hsi$1@speranza.aioe.org> <XnsA2A364854EA0Eeejj99@194.109.133.133> <l9jumc$rbe$1@speranza.aioe.org> <XnsA2A3ACC496F85eejj99@194.109.133.133> <l9ko3r$vdt$1@speranza.aioe.org>

Show all headers | View raw


On 2013-12-27 15:32 emf wrote:
> On 2013-12-27 10:59 Evertjan. wrote:
>> emf <emfril@gmail.com> wrote on 27 dec 2013 in comp.lang.javascript:
>>
>>> On 2013-12-27 03:52 Evertjan. wrote:
>>>> emf <emfril@gmail.com> wrote on 27 dec 2013 in comp.lang.javascript:
>>>>
>>>>>        function leapDay(yyyy) {
>>>>>            var lDay;
>>>>>            lDay = ((yyyy % 4 === 0 && yyyy % 100 !== 0) || yyyy %
>>>>> 400 ===
>>>>>              0) ? 1 : 0;
>>>>>            return lDay;
>>>>>          }
>>>>
>>>> Better call this isLeapYear(y),
>>>> [I presume that is what you ment]
>>>> use the Javascript Date object,
>>>> and have it return true/false:
>>>> [warning: Javascript Januari = month 0]
>>>>
>>>> function isLeapYear(y) {
>>>>      return !(new Date(y, 1, 29).getMonth()-1);
>>>> };
>>>>
>>>>
>>>>>          function isValid(yyyy, mm, dd) {
>>>>>            var valid;
>>>>>            if (yyyy > 0 && mm > 0 && mm <= 12 && dd > 0 && dd <= 31
>>>>>              && !(dd === 31 && (mm === 4 || mm === 6 || mm === 9 ||
>>>>>              mm === 11)) && !(mm === 2 && dd > 28 + leapDay(yyyy))) {
>>>>>              valid = true;
>>>>>            } else {
>>>>>              valid = false;
>>>>>            }
>>>>>            return valid;
>>>>>          }
>>>>
>>>> same objection to dubious function naming
>>>> and lack of possible compactness here:
>>>>
>>>> function isValidDate(y, m, d) {
>>>>      var t = new Date(y, m-1, d);
>>>>      return t.getMonth()+1 == m  &&  t.getDate() == d;
>>>> };
>>>>
>>>> if you prefer,
>>>> [and if you still need the isLeapDayYear at all?]
>>>> you could now also do:
>>>>
>>>> function isLeapYear(y) {
>>>>      return isValidDate(y, 2, 29);
>>>> };
>>>
>>> I first wrote my date subroutines in QBasic in the early '90s soon after
>>> taking a 1 credit course at a Community College. I've kept updating them
>>> as my understanding of programming changed over the years, as I do with
>>> the code of my webpages. Their latest reincarnation is in the JavaScript
>>> program:
>>>
>>> https://files.nyu.edu/emf202/public/js/dateCalculator.html
>>>
>>> which still works perfectly well and it has historical importance for
>>> me, besides presenting a historian's view on the issue. I haven't,
>>> however, updated the page for some time, and I am well aware I need to
>>> do it, because since I wrote it I've learned Java, which modified my
>>> views for variable names etc. a lot.
>>>
>>> Every time I visit this newsgroup and the issue comes up, Dr. John
>>> Stockton always finds some (valid) reason to express his dissatisfaction
>>> with my program, and I've come to accept it as an inevitable fact of
>>> life.
>>>
>>> I wish I would delve now on your suggestions, but it will have to wait
>>> until I decide to sit down and revise the whole date program.
>>
>> Dear Eustace,
>>
>> Then why do you post those functions, if not to discuss them in this
>> discussion group?
>
> You are right. I made a mistake. I should have included just 1 line in
> the code:
>
> <script type="text/javascript" src="dateCalculations.js"></script>
>
> so that I wouldn't inadvertently have shifted the focus away from the
> immediate problem. Here is the revised code with 3 new alerts:
>
> <!DOCTYPE html>
> <html>
>    <head><meta charset="utf-8" />
>      <title>Read File</title>
>      <script type="text/javascript" src="dateCalculations.js"></script>
>      <script type="text/javascript">
>
>        var reader, ephem = [];
>        reader = new XMLHttpRequest();
>
>        function ephemArray(data) {
>          var i, j, birthday, saturn, uranus;
>          for (i = 0; i < data.length / 22; i += 1) {
>            ephem[i] = [];
>          }
>          for (i = 0; i < data.length / 22; i += 1) {
>            j = i * 22;
>            birthday = data.substr(j, 8);
>            saturn = data.substr(j + 9, 5);
>            uranus = data.substr(j + 15, 5);
>            ephem[i][0] = birthday;
>            ephem[i][1] = saturn;
>            ephem[i][2] = uranus;
>          }
>          alert("1 " + ephem.length);
>        }
>
>        function loadData() {
>          var data;
>          if(reader.readyState === 4) {
>            data = reader.responseText;
>            ephemArray(data);
>          }
>        }
>
>        function loadFile() {
>          reader.open('get', 'ephemeris.csv', true);
>          reader.send(null);
>        }
>
>        function findBDay() {
>          var yyyy, mm, dd, yyyyS, mmS, ddS, birthday, i;
>          yyyy = +document.dataForm.yField.value;
>          mm = +document.dataForm.mField.value;
>          dd = +document.dataForm.dField.value;
>          if ( ((yyyy < 1900) || (yyyy > 2049)) || (!isValid(yyyy, mm,
>            dd)) ) {
>            i = -1;
>          } else {
>            yyyyS = yyyy.toString();
>            mmS = (mm < 10) ? "0" + mm : mm;
>            ddS = (dd < 10) ? "0" + dd : dd;
>            document.dataForm.mField.value = mmS;
>            document.dataForm.dField.value = ddS;
>            birthday = yyyyS + mmS + ddS;
> alert("3 " + ephem.length);
>            for (i = 0; i < ephem.length; i += 1) {
>              if (birthday === ephem[i][0]) {
>                break;
>              }
>            }
>          }
>          return i;
>        }
>
>        function findBirthData() {
>          var bDay;
>          loadFile();
>          reader.onreadystatechange = loadData;
> alert("2 " + ephem.length);
>          bDay = findBDay();
>          if (bDay >= 0) {
>            document.dataForm.outputArea.value +=
>              "\n" + ephem[bDay][0] + " " + ephem[bDay][1] + " " +
>              ephem[bDay][2];
>          } else {
>            document.dataForm.outputArea.value +=
>              "\n" + "Invalid entry";
>          }
>        }
>      </script>
>      </head>
>      <body onLoad="document.dataForm.outputArea.value='';">
>        <form name="dataForm" action="">
>          Enter birthday (yyyy-m-d):
>          <input type="text" name="yField" value="" size=4> -
>          <input type="text" name="mField" value="" size=2> -
>          <input type="text" name="dField" value="" size=2>
>          <input type="button" value="  Find  "
>            onclick="findBirthData()">
>          <textarea name="outputArea" rows="16" cols="43"></textarea></td>
>        </form>
>      </body>
> </html>
>
> I have included 3 alerts to get the ephem.length. In alert 1 the length
> is given correctly as 54787. In alert 2, before calling the findBDay
> functions it has become 0! In alert 3, inside the bDay function, it has
> reverted to 54787.
>
> In the chart below - means that the alert has been commented out. OK
> means that I get results without having to click again on the button.
>
> alert 1    alert 2    alert 3    results
> 54787      0          54787      OK
> -          0          54787      OK
> 54787      -          0          OK
> 54787      0          -          OK
> -          -          0          OK
> -          0          -          OK
> -          -          0          OK

this is duplicate; the correct is:
   54787      -          -          !OK

> -          -          -          !OK
>
> So if any one alert is executed, we get results with the first click.
>
> Alert 1 always gives 54787.
>
> Alert 2 always gives 0.
>
> Alert 3 gives 54787 if alert 2 has execute before, otherwise it gives 0.
>
> We get results on the first click if any of the 3 alerts has been executed.
>
> Can anybody make sense out of this? I cannot.
>
> Eustace

Forget the other alerts. Just add 2 alerts before printing in the output 
area:

         if (bDay >= 0) {
alert(ephem.length);
alert(ephem.length);
           document.dataForm.outputArea.value +=
             "\n" + ephem[bDay][0] + " " + ephem[bDay][1] + " "
             + ephem[bDay][2];
         } else {
           document.dataForm.outputArea.value +=
           "\n" + "Invalid entry";
         }

The first will return 0 and the second 54787! Clearly the first alert 
restores the array. This should be a JavaScript bug.

If instead of these 2 alerts we introduce these 2:

alert(typeof(ephem[1]));
alert(typeof(ephem[1]));

they return undefined and object.

So far I have found 2 methods of restoring the array: Introducing an 
alert in a later function, or double=clicking the button.I am looking 
for a possible third way of bypassing the problem that does not require 
user intervention, though it seems I may have to settle with requesting 
the user to double-click the Find button.

emf

-- 
Google's top Spherical Triangle Calculator search result!
https://files.nyu.edu/emf202/public/js/spherical.html

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Compressing js file? emf <emfril@gmail.com> - 2013-12-23 14:31 -0500
  Re: Compressing js file? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2013-12-23 22:08 -0200
  Re: Compressing js file? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-12-23 16:40 -0800
    Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-24 13:23 -0500
    Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-26 21:56 -0500
      Re: Compressing js file? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-12-27 09:52 +0100
        Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-27 08:18 -0500
          Re: Compressing js file? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-12-27 16:59 +0100
            Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-27 15:32 -0500
              Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-28 15:12 -0500
                Re: Compressing js file? emf <emfril@gmail.com> - 2014-01-01 02:17 -0500
        Re: Compressing js file? Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-12-28 20:20 +0000
      XHR with timing issues (was: Compressing js file?) Christoph Michael Becker <cmbecker69@arcor.de> - 2013-12-27 22:33 +0100
        Re: XHR with timing issues (was: Compressing js file?) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-27 23:26 +0100
          Re: XHR with timing issues Christoph Michael Becker <cmbecker69@arcor.de> - 2013-12-28 12:08 +0100
            Re: XHR with timing issues emf <emfril@gmail.com> - 2013-12-28 09:04 -0500
  Re: Compressing js file? wolfgang zeidler <invalid@invalid.invalid> - 2013-12-27 22:33 +0100
    Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-28 00:16 -0500
      Re: Compressing js file? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-12-28 11:13 +0100
        Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-28 11:26 -0500
          Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-28 13:53 -0500
            Re: Compressing js file? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-12-28 21:00 +0100
              Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-29 21:47 -0500
                Re: Compressing js file? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-12-31 14:05 -0800
                Re: Compressing js file? emf <emfril@gmail.com> - 2014-01-01 02:50 -0500
                Re: Compressing js file? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-01-01 01:16 -0800
                Re: Compressing js file? emf <emfril@gmail.com> - 2014-01-01 08:13 -0500
                Re: Compressing js file? Tim Streater <timstreater@greenbee.net> - 2014-01-01 14:17 +0000
                Re: Compressing js file? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-01-01 15:31 -0800
                Re: Compressing js file? emf <emfril@gmail.com> - 2014-01-01 18:38 -0500
                Re: Compressing js file? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-01-01 15:45 -0800
                Re: Compressing js file? emf <emfril@gmail.com> - 2014-01-02 11:43 -0500
                Re: Compressing js file? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-01-02 09:34 -0800
                OT: Compressing js file? Christoph Michael Becker <cmbecker69@arcor.de> - 2014-01-02 19:52 +0100
                Re: Compressing js file? emf <emfril@gmail.com> - 2014-01-03 07:19 -0500
                Re: Compressing js file? emf <emfril@gmail.com> - 2014-01-03 07:31 -0500
                Re: Compressing js file? Tim Streater <timstreater@greenbee.net> - 2014-01-02 09:14 +0000
                Re: Compressing js file? Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-01 16:25 +0000
                Re: Compressing js file? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-01-01 21:36 +0100
          Re: Compressing js file? wolfgang zeidler <invalid@invalid.invalid> - 2013-12-29 20:06 +0100
            Re: Compressing js file? wolfgang zeidler <invalid@invalid.invalid> - 2013-12-29 20:27 +0100
        Re: Compressing js file? Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-12-29 18:02 +0000
          Re: Compressing js file? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-12-30 18:17 +0100
            Re: Compressing js file? John Harris <niam@jghnorth.org.uk.invalid> - 2013-12-31 10:52 +0000
            Re: Compressing js file? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-12-31 13:38 +0000
              Re: Compressing js file? John Harris <niam@jghnorth.org.uk.invalid> - 2013-12-31 15:02 +0000
                Re: Compressing js file? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-01-01 16:42 +0000
                Re: Compressing js file? Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-01-01 21:32 +0000
            Re: Compressing js file? Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-12-31 21:44 +0000

csiph-web