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


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

How to manipulate integer that sometimes Nan and sometimes have a value?

Started byjonas.thornvall@gmail.com
First post2015-09-25 07:31 -0700
Last post2015-09-27 09:02 -0700
Articles 20 on this page of 44 — 8 participants

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


Contents

  How to manipulate integer that sometimes Nan and sometimes have a value? jonas.thornvall@gmail.com - 2015-09-25 07:31 -0700
    Re: How to manipulate integer that sometimes Nan and sometimes have a value? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-09-25 17:09 +0200
      Re: How to manipulate integer that sometimes Nan and sometimes have a value? jonas.thornvall@gmail.com - 2015-09-25 14:43 -0700
        Re: How to manipulate integer that sometimes Nan and sometimes have a value? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-09-26 08:54 +0200
      Re: How to manipulate integer that sometimes Nan and sometimes have a value? Erwin Moller <erwinmollerusenet@xs4all.nl> - 2015-09-30 15:04 +0200
        Re: How to manipulate integer that sometimes Nan and sometimes have a value? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-09-30 21:13 +0200
          Re: How to manipulate integer that sometimes Nan and sometimes have a value? Erwin Moller <erwinmollerusenet@xs4all.nl> - 2015-10-01 10:44 +0200
            Re: How to manipulate integer that sometimes Nan and sometimes have a value? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-10-01 13:56 +0200
              Re: How to manipulate integer that sometimes Nan and sometimes have a value? John Harris <niam@jghnorth.org.uk.invalid> - 2015-10-02 11:09 +0100
                Re: How to manipulate integer that sometimes Nan and sometimes have a value? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-02 13:55 +0100
                Re: How to manipulate integer that sometimes Nan and sometimes have a value? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-10-02 16:34 +0200
    Re: How to manipulate integer that sometimes Nan and sometimes have a value? Danny <dann90038@gmail.com> - 2015-09-25 15:11 -0700
      Re: How to manipulate integer that sometimes Nan and sometimes have a value? jonas.thornvall@gmail.com - 2015-09-25 17:50 -0700
        Re: How to manipulate integer that sometimes Nan and sometimes have a value? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-09-26 08:59 +0200
          Re: How to manipulate integer that sometimes Nan and sometimes have a value? jonas.thornvall@gmail.com - 2015-09-26 04:25 -0700
            Re: How to manipulate integer that sometimes Nan and sometimes have a value? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-09-26 15:00 +0200
              Re: How to manipulate integer that sometimes Nan and sometimes have a value? jonas.thornvall@gmail.com - 2015-09-26 06:15 -0700
                Re: How to manipulate integer that sometimes Nan and sometimes have a value? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-09-26 15:34 +0200
                  Re: How to manipulate integer that sometimes Nan and sometimes have a value? jonas.thornvall@gmail.com - 2015-09-26 08:06 -0700
                  Re: How to manipulate integer that sometimes Nan and sometimes have a value? Tim Streater <timstreater@greenbee.net> - 2015-09-26 18:10 +0100
                    Re: How to manipulate integer that sometimes Nan and sometimes have a value? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-09-26 22:53 +0200
                      Re: How to manipulate integer that sometimes Nan and sometimes have a value? Tim Streater <timstreater@greenbee.net> - 2015-09-26 22:37 +0100
                        Re: How to manipulate integer that sometimes Nan and sometimes have a value? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-09-27 10:05 +0200
                          Re: How to manipulate integer that sometimes Nan and sometimes have a value? jonas.thornvall@gmail.com - 2015-09-27 08:42 -0700
                          Re: How to manipulate integer that sometimes Nan and sometimes have a value? Tim Streater <timstreater@greenbee.net> - 2015-09-27 17:18 +0100
        Re: How to manipulate integer that sometimes Nan and sometimes have a value? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-26 10:59 +0100
          Re: How to manipulate integer that sometimes Nan and sometimes have a value? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-09-26 13:15 +0200
            Re: How to manipulate integer that sometimes Nan and sometimes have a value? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-26 14:58 +0100
              Re: How to manipulate integer that sometimes Nan and sometimes have a value? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-09-26 16:57 +0200
          Re: How to manipulate integer that sometimes Nan and sometimes have a value? jonas.thornvall@gmail.com - 2015-09-26 04:28 -0700
            Re: How to manipulate integer that sometimes Nan and sometimes have a value? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-09-26 15:11 +0200
              Re: How to manipulate integer that sometimes Nan and sometimes have a value? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-09-26 17:19 +0200
                Re: How to manipulate integer that sometimes Nan and sometimes have a value? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-09-26 22:51 +0200
                  Re: How to manipulate integer that sometimes Nan and sometimes have a value? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-09-27 13:50 +0200
            Re: How to manipulate integer that sometimes Nan and sometimes have a value? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-26 20:51 +0100
              Re: How to manipulate integer that sometimes Nan and sometimes have a value? jonas.thornvall@gmail.com - 2015-09-28 22:45 -0700
                Re: How to manipulate integer that sometimes Nan and sometimes have a value? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-09-29 12:36 +0200
                Re: How to manipulate integer that sometimes Nan and sometimes have a value? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-29 12:48 +0100
          Re: How to manipulate integer that sometimes Nan and sometimes have a value? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-09-26 14:43 +0200
            Re: How to manipulate integer that sometimes Nan and sometimes have a value? jonas.thornvall@gmail.com - 2015-09-26 06:06 -0700
              Re: How to manipulate integer that sometimes Nan and sometimes have a value? John Harris <niam@jghnorth.org.uk.invalid> - 2015-09-27 14:06 +0100
                Re: How to manipulate integer that sometimes Nan and sometimes have a value? jonas.thornvall@gmail.com - 2015-09-27 08:50 -0700
                Re: How to manipulate integer that sometimes Nan and sometimes have a value? jonas.thornvall@gmail.com - 2015-09-27 08:53 -0700
                  Re: How to manipulate integer that sometimes Nan and sometimes have a value? jonas.thornvall@gmail.com - 2015-09-27 09:02 -0700

Page 1 of 3  [1] 2 3  Next page →


#28707 — How to manipulate integer that sometimes Nan and sometimes have a value?

Fromjonas.thornvall@gmail.com
Date2015-09-25 07:31 -0700
SubjectHow to manipulate integer that sometimes Nan and sometimes have a value?
Message-ID<9060ce04-2f9e-4554-be83-2f69c213424f@googlegroups.com>
This is how i chosen to do it, is there a better way?

if (isNaN(addOne[i])) addOne[i] = 0; addOne[i] = addOne[i]+1;

[toc] | [next] | [standalone]


#28708

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2015-09-25 17:09 +0200
Message-ID<XnsA520AE7AD610Feejj99@194.109.6.166>
In reply to#28707
jonas.thornvall@gmail.com wrote on 25 Sep 2015 in comp.lang.javascript:

> This is how i chosen to do it, 

To do what?

> is there a better way?

I am reasonably sure there is, 
but that depends on the answer of the first Q.
 
> if (isNaN(addOne[i])) addOne[i] = 0; addOne[i] = addOne[i]+1;

This would do the same, 
[using kiss, the array seems not to be a part of your Q]:

if (isNaN(z))
    z = 0; 
z++;

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

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


#28711

Fromjonas.thornvall@gmail.com
Date2015-09-25 14:43 -0700
Message-ID<45a95b1e-8d36-419e-8d09-c86c23e66acb@googlegroups.com>
In reply to#28708
Den fredag 25 september 2015 kl. 17:09:22 UTC+2 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 25 Sep 2015 in comp.lang.javascript:
> 
> > This is how i chosen to do it, 
> 
> To do what?
> 
> > is there a better way?
> 
> I am reasonably sure there is, 
> but that depends on the answer of the first Q.
>  
> > if (isNaN(addOne[i])) addOne[i] = 0; addOne[i] = addOne[i]+1;
> 
> This would do the same, 
> [using kiss, the array seems not to be a part of your Q]:
> 
> if (isNaN(z))
>     z = 0; 
> z++;
> 
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

Well that is basicly the same?
if (isNaN(addOne[i])) addOne[i]=0;
addOne[i++] //Is that one even ok?
 

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


#28718

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2015-09-26 08:54 +0200
Message-ID<XnsA5215AB3E82CDeejj99@194.109.6.166>
In reply to#28711
jonas.thornvall@gmail.com wrote on 25 Sep 2015 in comp.lang.javascript:

> Den fredag 25 september 2015 kl. 17:09:22 UTC+2 skrev Evertjan.:
>> jonas.thornvall@gmail.com wrote on 25 Sep 2015 in comp.lang.javascript:
>> 
>> > This is how i chosen to do it, 
>> 
>> To do what?
>> 
>> > is there a better way?
>> 
>> I am reasonably sure there is, 
>> but that depends on the answer of the first Q.
>>  
>> > if (isNaN(addOne[i])) addOne[i] = 0; addOne[i] = addOne[i]+1;
>> 
>> This would do the same, 
>> [using kiss, the array seems not to be a part of your Q]:
>> 
>> if (isNaN(z))
>>     z = 0; 
>> z++;
> 
> Well that is basicly the same?

Only if you had responded affirmative on my first Q. 

"Basically" all Javascript is "the same" 
as it is just code doing something.

> if (isNaN(addOne[i])) addOne[i]=0;
> addOne[i++] //Is that one even ok?

addOne is a strange name for an array!

The statement:

addOne[i++];

will do NOTHING however and is equivalent to:

;

Please think before you post something.

 



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

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


#28764

FromErwin Moller <erwinmollerusenet@xs4all.nl>
Date2015-09-30 15:04 +0200
Message-ID<560bddeb$0$23841$e4fe514c@news.xs4all.nl>
In reply to#28708
On 9/25/2015 5:09 PM, Evertjan. wrote:
> jonas.thornvall@gmail.com wrote on 25 Sep 2015 in comp.lang.javascript:
>
>> This is how i chosen to do it,
>
> To do what?
>
>> is there a better way?
>
> I am reasonably sure there is,
> but that depends on the answer of the first Q.
>
>> if (isNaN(addOne[i])) addOne[i] = 0; addOne[i] = addOne[i]+1;
>
> This would do the same,
> [using kiss, the array seems not to be a part of your Q]:
>
> if (isNaN(z))
>      z = 0;
> z++;
>

(A late and barely relevant response)

Just curious, are you one of those that omit curly brackets whenever 
possible?
If yes, why?


Regards,
Erwin Moller

-- 
"That which can be asserted without evidence, can be dismissed without 
evidence."
-- Christopher Hitchens

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


#28766

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2015-09-30 21:13 +0200
Message-ID<XnsA525D7E5B774Eeejj99@194.109.6.166>
In reply to#28764
Erwin Moller <erwinmollerusenet@xs4all.nl> wrote on 30 Sep 2015 in 
comp.lang.javascript:

> On 9/25/2015 5:09 PM, Evertjan. wrote:
>> jonas.thornvall@gmail.com wrote on 25 Sep 2015 in comp.lang.javascript:
>>
>>> This is how i chosen to do it,
>>
>> To do what?
>>
>>> is there a better way?
>>
>> I am reasonably sure there is,
>> but that depends on the answer of the first Q.
>>
>>> if (isNaN(addOne[i])) addOne[i] = 0; addOne[i] = addOne[i]+1;

[Above 1]

>> This would do the same,
>> [using kiss, the array seems not to be a part of your Q]:
>>
>> if (isNaN(z))
>>      z = 0;
>> z++;

[above 2]

> (A late and barely relevant response)
> 
> Just curious, are you one of those that omit curly brackets whenever 
> possible?
> If yes, why?

Why not?

"Above 1" shows how NOT to do it.

"Above 2" shows a perfectly reasonable way how to do it.

Those curly things feel a bit like things that are not to be pronounced.

Whenever possible, 
I like to see and do the good things in and of life,
absolutely including programmable cyberlife,
and foremostly including having a good laugh about 
those that think in near absolutes.

That seldom is impossible.

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

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


#28770

FromErwin Moller <erwinmollerusenet@xs4all.nl>
Date2015-10-01 10:44 +0200
Message-ID<560cf259$0$23792$e4fe514c@news.xs4all.nl>
In reply to#28766
On 9/30/2015 9:13 PM, Evertjan. wrote:
> Erwin Moller <erwinmollerusenet@xs4all.nl> wrote on 30 Sep 2015 in
> comp.lang.javascript:
>
>> On 9/25/2015 5:09 PM, Evertjan. wrote:
>>> jonas.thornvall@gmail.com wrote on 25 Sep 2015 in comp.lang.javascript:
>>>
>>>> This is how i chosen to do it,
>>>
>>> To do what?
>>>
>>>> is there a better way?
>>>
>>> I am reasonably sure there is,
>>> but that depends on the answer of the first Q.
>>>
>>>> if (isNaN(addOne[i])) addOne[i] = 0; addOne[i] = addOne[i]+1;
>
> [Above 1]
>
>>> This would do the same,
>>> [using kiss, the array seems not to be a part of your Q]:
>>>
>>> if (isNaN(z))
>>>       z = 0;
>>> z++;
>
> [above 2]
>
>> (A late and barely relevant response)
>>
>> Just curious, are you one of those that omit curly brackets whenever
>> possible?
>> If yes, why?
>
> Why not?
>
> "Above 1" shows how NOT to do it.
>
> "Above 2" shows a perfectly reasonable way how to do it.
>
> Those curly things feel a bit like things that are not to be pronounced.
>
> Whenever possible,
> I like to see and do the good things in and of life,
> absolutely including programmable cyberlife,
> and foremostly including having a good laugh about
> those that think in near absolutes.
>
> That seldom is impossible.
>

I bow in your wisdom. ;-)

This is not about what is possible, but just about clarity.
But each to his/her own.

Here is a real life example of troubles coming with that style:
https://blog.codecentric.de/en/2014/02/curly-braces/

Regards,
Erwin Moller

-- 
"That which can be asserted without evidence, can be dismissed without 
evidence."
-- Christopher Hitchens

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


#28771

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2015-10-01 13:56 +0200
Message-ID<XnsA5268DC2F5A52eejj99@194.109.6.166>
In reply to#28770
Erwin Moller <erwinmollerusenet@xs4all.nl> wrote on 01 Oct 2015 in 
comp.lang.javascript:

> On 9/30/2015 9:13 PM, Evertjan. wrote:
>> Erwin Moller <erwinmollerusenet@xs4all.nl> wrote on 30 Sep 2015 in
>> comp.lang.javascript:
>>
>>> On 9/25/2015 5:09 PM, Evertjan. wrote:
>>>> jonas.thornvall@gmail.com wrote on 25 Sep 2015 in comp.lang.javascript:
>>>>
>>>>> This is how i chosen to do it,
>>>>
>>>> To do what?
>>>>
>>>>> is there a better way?
>>>>
>>>> I am reasonably sure there is,
>>>> but that depends on the answer of the first Q.
>>>>
>>>>> if (isNaN(addOne[i])) addOne[i] = 0; addOne[i] = addOne[i]+1;
>>
>> [Above 1]
>>
>>>> This would do the same,
>>>> [using kiss, the array seems not to be a part of your Q]:
>>>>
>>>> if (isNaN(z))
>>>>       z = 0;
>>>> z++;
>>
>> [above 2]
>>
>>> (A late and barely relevant response)
>>>
>>> Just curious, are you one of those that omit curly brackets whenever
>>> possible?
>>> If yes, why?
>>
>> Why not?
>>
>> "Above 1" shows how NOT to do it.
>>
>> "Above 2" shows a perfectly reasonable way how to do it.
>>
>> Those curly things feel a bit like things that are not to be pronounced.
>>
>> Whenever possible,
>> I like to see and do the good things in and of life,
>> absolutely including programmable cyberlife,
>> and foremostly including having a good laugh about
>> those that think in near absolutes.
>>
>> That seldom is impossible.
>>
> 
> I bow in your wisdom. ;-)
> 
> This is not about what is possible, but just about clarity.
> But each to his/her own.
> 
> Here is a real life example of troubles coming with that style:
> https://blog.codecentric.de/en/2014/02/curly-braces/

Everything is dangerous in the hands of the incompetent.

the curly things are often felt as part of the if() statement,
but they are not.

Methinks cascading curly things,
excepting those on the heads of fair maidens,
are far more accident-prone than neatly indented code.

['braces' are a way of making fair maidens even more fair,
unfairly reducing that fairness to cuteness for the time being]

The curly things in JS are a only necessary when
making a single compound statement consisting of multiple statements,
and so are superfluous around single statements.

Thinking they are required around single statements when such statement 
[accidently] is the "object" of an if-statement, shows a respectable lack of 
understanding of the scripting flow.

[Ideally, imho, they should not be required around a single-statemented 
function-declaration, as a should just define the compound statement in the 
function, but helas, that wasn't to be the case.]

So:

if (a)
  if (b)
    if (c)
      doD();

... is a nice and simple form of a single compound statement.

if (a)
  {doA();
    if (b)
      if (c)
        doD();
  };

... here the curly things are only needed to make a compound substatement 
work.

if (a)
  {doA();doB();};
if (b)
  {doB();doE();};
if (c)
  {doC();};

Here I would allow the unnecessary third statement's curly things
just for symmetry's sake.

Thinking of nicely visual modularity and so for debuggability,
perhaps the "object" of a if() statement should always be a single 
statement, preferably a adequately named function.

In practice, we all, and more than never, write dirty code,
even where the debugging process nullifies the logic of the urge for 
quickness.

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

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


#28776

FromJohn Harris <niam@jghnorth.org.uk.invalid>
Date2015-10-02 11:09 +0100
Message-ID<7uls0b16v45mvlc4t036gq054mpc16scc8@4ax.com>
In reply to#28771
On Thu, 01 Oct 2015 13:56:08 +0200, "Evertjan."
<exxjxw.hannivoort@inter.nl.net> wrote:

  <snip>
>... here the curly things are only needed to make a compound substatement 
>work.
>
>if (a)
>  {doA();doB();};
>if (b)
>  {doB();doE();};
>if (c)
>  {doC();};
>
>Here I would allow the unnecessary third statement's curly things
>just for symmetry's sake.

You've missed out the well known horror :
  if (b) {
    doB(); doE();
    }

:-)


>Thinking of nicely visual modularity and so for debuggability,
>perhaps the "object" of a if() statement should always be a single 
>statement, preferably a adequately named function.
  <snip>

As  {...} *is* a single statement you'll have difficulty defining the
"object" of an if() statement. [See 'block' and 'if' in ECMA 262].

  John

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


#28785

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2015-10-02 13:55 +0100
Message-ID<87a8s1sa3r.fsf@bsb.me.uk>
In reply to#28776
John Harris <niam@jghnorth.org.uk.invalid> writes:
<snip>
> You've missed out the well known horror :
>   if (b) {
>     doB(); doE();
>     }
>
> :-)

And let's not forget

  if (Sinatra) { doB(); doB(); Do(); }

:-)

<snip>
-- 
Ben.

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


#28786

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2015-10-02 16:34 +0200
Message-ID<XnsA527A895D8A36eejj99@194.109.6.166>
In reply to#28776
John Harris <niam@jghnorth.org.uk.invalid> wrote on 02 Oct 2015 in 
comp.lang.javascript:

> You've missed out the well known horror :
>   if (b) {
>     doB(); doE();
>     }

The horror is only in the mind 
of the ones not understanding the syntax,
because the 'object-statement' of 'if(boolean)'
is ALWAYS a single statement,
so if you need more statements you convert them with
{} to a single compount statement:

if (b)
   { doB(); doE(); };

If there is only a single statement, then the curly things are purely 
decorative, and obsure the issue of showing short and correct syntax.

> As  {...} *is* a single statement you'll have difficulty defining the
> "object" of an if() statement. 

I should have named it "object-statement".


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

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


#28712

FromDanny <dann90038@gmail.com>
Date2015-09-25 15:11 -0700
Message-ID<4f31ec16-109f-43b2-9d50-b39d4fb47f84@googlegroups.com>
In reply to#28707
to jonas.t

in short, if the value is an integer, it will never return NaN.
What if may be happening in your case, is that the object gets
something else other than a numeric value.

but a solution depends on what the context for all that is
and you haven't given us context or relevant code of the matter

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


#28716

Fromjonas.thornvall@gmail.com
Date2015-09-25 17:50 -0700
Message-ID<3cf46737-de54-489e-9d9d-89413b18c099@googlegroups.com>
In reply to#28712
Den lördag 26 september 2015 kl. 00:11:31 UTC+2 skrev Danny:
> to jonas.t
> 
> in short, if the value is an integer, it will never return NaN.
> What if may be happening in your case, is that the object gets
> something else other than a numeric value.
> 
> but a solution depends on what the context for all that is
> and you haven't given us context or relevant code of the matter

Well sometimes the index of the array is empty for the leading position, it is an carry operation.

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


#28719

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2015-09-26 08:59 +0200
Message-ID<XnsA5215B83443E2eejj99@194.109.6.166>
In reply to#28716
jonas.thornvall@gmail.com wrote on 26 Sep 2015 in comp.lang.javascript:

> Well sometimes the index of the array is empty for the leading position,
> it is an carry operation. 

An index of an array CANNOT be empty,
because then it would not be an index. 

Till you are in a leading position,
I would not trust you to do an operation.

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

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


#28723

Fromjonas.thornvall@gmail.com
Date2015-09-26 04:25 -0700
Message-ID<1261b8e1-1559-4539-9225-24bccd6c7f0d@googlegroups.com>
In reply to#28719
Den lördag 26 september 2015 kl. 08:59:50 UTC+2 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 26 Sep 2015 in comp.lang.javascript:
> 
> > Well sometimes the index of the array is empty for the leading position,
> > it is an carry operation. 
> 
> An index of an array CANNOT be empty,
> because then it would not be an index. 

Ok ok, Evertjan the element of index is NaN.

> Till you are in a leading position,
> I would not trust you to do an operation.

Well that is the problem with doing carry operations using array elements as digitplaces, you do not know if the element for the index previously occupied by an integer or not. And if not you have to initialise it to an integer. The main case is of course you add one to the array element. But if it is a leading carry operation the element for the index will hold NaN.
 
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

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


#28726

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2015-09-26 15:00 +0200
Message-ID<XnsA52198BA81D52eejj99@194.109.6.166>
In reply to#28723
jonas.thornvall@gmail.com wrote on 26 Sep 2015 in comp.lang.javascript:

>> An index of an array CANNOT be empty,
>> because then it would not be an index. 
> 
> Ok ok, Evertjan the element of index is NaN.

Well, I think it pays to be more exact.

"The element OF an array HAVING a certain index."

>> Till you are in a leading position,
>> I would not trust you to do an operation.
> 
> Well that is the problem with doing carry operations using array
> elements as digitplaces, you do not know if the element for the index
> previously occupied by an integer or not.

You should know, otherways your code is not logical.

If a specific array-element is initialized, 
how can it be occupied by something else 
than what you want it to initialize with?

If a specific array-element is not initialized [or deleted],
it is not "empty" but "undefined".

> And if not you have to initialise it to an integer.

Only if that integer is the result of your computation.

Putting 0 into "undefined" array-elements 
expects too much of your specific algorithm,
better make another algorithm for those cases.

> The main case is of course you add one to
> the array element.

Not at all "ofcourse". 
Perhaps you want it that way in this case,
then say so: "I want this and that".

> But if it is a leading carry operation 

What is a  "leading carry operation" 

> the element for the index will hold NaN. 

So it could hold the NaN-value?

I don't think so.

[The NaN-value being a special case of type Number.]

Could it hold a string or an object perhaps?

I don't believe that.
I think it the specific array-element is simply not intitialised, 
so when asked for it 

alert( myArr[i] );

it returns 'undefined'.

So do this:

if (typeof myArr[i] != 'undefined') ...


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

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


#28729

Fromjonas.thornvall@gmail.com
Date2015-09-26 06:15 -0700
Message-ID<ca0ea1d3-528e-4c06-ad28-2a3b5642cea3@googlegroups.com>
In reply to#28726
Den lördag 26 september 2015 kl. 15:01:42 UTC+2 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 26 Sep 2015 in comp.lang.javascript:
> 
> >> An index of an array CANNOT be empty,
> >> because then it would not be an index. 
> > 
> > Ok ok, Evertjan the element of index is NaN.
> 
> Well, I think it pays to be more exact.
> 
> "The element OF an array HAVING a certain index."
> 
> >> Till you are in a leading position,
> >> I would not trust you to do an operation.
> > 
> > Well that is the problem with doing carry operations using array
> > elements as digitplaces, you do not know if the element for the index
> > previously occupied by an integer or not.
> 
> You should know, otherways your code is not logical.
> 
> If a specific array-element is initialized, 
> how can it be occupied by something else 
> than what you want it to initialize with?
> 
> If a specific array-element is not initialized [or deleted],
> it is not "empty" but "undefined".
> 
> > And if not you have to initialise it to an integer.
> 
> Only if that integer is the result of your computation.
> 
> Putting 0 into "undefined" array-elements 
> expects too much of your specific algorithm,
> better make another algorithm for those cases.
> 
> > The main case is of course you add one to
> > the array element.
> 
> Not at all "ofcourse". 
> Perhaps you want it that way in this case,
> then say so: "I want this and that".
> 
> > But if it is a leading carry operation 
> 
> What is a  "leading carry operation" 
> 

A leading digit carry operation adding arrOne=[9] and arrTwo[1] using base 10.

If each element only allowed to hold the digitspace within base *10* -> 0-9 then there will be a carry operation to next index element and that element is undefined, but return NaN if you try to add, "without initialise it to 0".

> > the element for the index will hold NaN. 
> 
> So it could hold the NaN-value?
> 
> I don't think so.
> 
> [The NaN-value being a special case of type Number.]
> 
> Could it hold a string or an object perhaps?
> 
> I don't believe that.
> I think it the specific array-element is simply not intitialised, 
> so when asked for it 
> 
> alert( myArr[i] );
> 
> it returns 'undefined'.
> 
> So do this:
> 
> if (typeof myArr[i] != 'undefined') ...
> 
> 
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

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


#28730

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2015-09-26 15:34 +0200
Message-ID<XnsA5219E7CBAC2eejj99@194.109.6.166>
In reply to#28729
jonas.thornvall@gmail.com wrote on 26 Sep 2015 in comp.lang.javascript:

>> What is a  "leading carry operation" 
>> 
> 
> A leading digit carry operation adding arrOne=[9] and arrTwo[1] using
> base 10. 
 
So you define "leading digit carry operation" here, it is not something in 
geneal knowledge?

Please keep from using your private terminology without initializing it 
properly.

> If each element only allowed to hold the digitspace within base *10* ->
> 0-9 then there will be a carry operation to next index element and that
> element is undefined, but return NaN if you try to add, "without
> initialise it to 0". 

Ofcourse you cannot add 1 to a nonexisting value,
so that is not a problem, but univeral mathemeatical logic.

Expecting a nonexisting value to be zero or whatever is ludicrous.

You should be glad that Javascript does not crash or error out,
but gives you the NaN-value, but it stays bad programming.

====================

Long gone are the days that
"All numerical variable are created zero"
and 
"All people are created equal".

The first is untrue because Old Style BASIC is no more,
the second is untrue because people are not created.

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

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


#28733

Fromjonas.thornvall@gmail.com
Date2015-09-26 08:06 -0700
Message-ID<679f0aa6-cbd7-4a76-80b5-592adf830eee@googlegroups.com>
In reply to#28730
Den lördag 26 september 2015 kl. 15:34:56 UTC+2 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 26 Sep 2015 in comp.lang.javascript:
> 
> >> What is a  "leading carry operation" 
> >> 
> > 
> > A leading digit carry operation adding arrOne=[9] and arrTwo[1] using
> > base 10. 
>  
> So you define "leading digit carry operation" here, it is not something in 
> geneal knowledge?

Well i think leading digit actually both defined and specific, and to get a carry when adding in base 10 the sum of operands have to be >=10


> Please keep from using your private terminology without initializing it 
> properly.
> 
> > If each element only allowed to hold the digitspace within base *10* ->
> > 0-9 then there will be a carry operation to next index element and that
> > element is undefined, but return NaN if you try to add, "without
> > initialise it to 0". 
> 
> Ofcourse you cannot add 1 to a nonexisting value,
> so that is not a problem, but univeral mathemeatical logic.
> 
> Expecting a nonexisting value to be zero or whatever is ludicrous.
> 
> You should be glad that Javascript does not crash or error out,
> but gives you the NaN-value, but it stays bad programming.
> 
> ====================
> 
> Long gone are the days that
> "All numerical variable are created zero"
> and 
> "All people are created equal".
> 
> The first is untrue because Old Style BASIC is no more,
> the second is untrue because people are not created.
> 
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

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


#28735

FromTim Streater <timstreater@greenbee.net>
Date2015-09-26 18:10 +0100
Message-ID<260920151810299395%timstreater@greenbee.net>
In reply to#28730
In article <XnsA5219E7CBAC2eejj99@194.109.6.166>, Evertjan.
<exxjxw.hannivoort@inter.nl.net> wrote:

>You should be glad that Javascript does not crash or error out,
>but gives you the NaN-value, but it stays bad programming.

Personally I'd prefer if it were possible to have javascript give an
exception when NaN is generated, for debugging purposes.

-- 
New Socialism consists essentially in being seen to have your heart in 
the right place whilst your head is in the clouds and your hand is in 
someone else's pocket.

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


Page 1 of 3  [1] 2 3  Next page →

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


csiph-web