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


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

Can i compare with an empty array element?

Started byjonas.thornvall@gmail.com
First post2016-03-10 23:58 -0800
Last post2016-03-14 06:00 -0700
Articles 3 — 2 participants

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


Contents

  Can i compare with an empty array element? jonas.thornvall@gmail.com - 2016-03-10 23:58 -0800
    Re: Can i compare with an empty array element? jonas.thornvall@gmail.com - 2016-03-11 00:16 -0800
      Re: Can i compare with an empty array element? Simon Blackwell <syblackwell@anywhichway.com> - 2016-03-14 06:00 -0700

#29887 — Can i compare with an empty array element?

Fromjonas.thornvall@gmail.com
Date2016-03-10 23:58 -0800
SubjectCan i compare with an empty array element?
Message-ID<9d670045-35dd-4279-a4e5-2e3cdae867e7@googlegroups.com>
function untangle_links(arr)
{
   printnode = new Array;
   var j = 0;
   var tempnode = 0;
   var tnode = new Array();
   for(var i = 0; i < nodes; i ++ )
   {
      for(var k = 0; k < tnode.length; k ++ )
      {
           if (arr[tempnode].nodelinks[j] == tnode[k])//Is this ok?
         {                                            //tnode[k] undefined or NaN?
            j ++ ;
         }
      }
      tempnode = arr[tempnode].nodelinks[j];
      tnode[tnode.length] = tempnode;
      printnode[i] = tempnode;
      j = 0;
   }
   return printnode;
} 

[toc] | [next] | [standalone]


#29888

Fromjonas.thornvall@gmail.com
Date2016-03-11 00:16 -0800
Message-ID<2613221c-bd10-4e41-8838-65cd64adde48@googlegroups.com>
In reply to#29887
Den fredag 11 mars 2016 kl. 08:58:27 UTC+1 skrev jonas.t...@gmail.com:
> function untangle_links(arr)
> {
>    printnode = new Array;
>    var j = 0;
>    var tempnode = 0;
>    var tnode = new Array();
>    for(var i = 0; i < nodes; i ++ )
>    {
>       for(var k = 0; k < tnode.length; k ++ )
>       {
>            if (arr[tempnode].nodelinks[j] == tnode[k])//Is this ok?
>          {                                            //tnode[k] undefined or NaN?
>             j ++ ;
>          }
>       }
>       tempnode = arr[tempnode].nodelinks[j];
>       tnode[tnode.length] = tempnode;
>       printnode[i] = tempnode;
>       j = 0;
>    }
>    return printnode;
> }

I do not think i should need a special case to compare with null, undefined or NaN. But you never know. I mean if it isn't the same it isn't.

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


#29981

FromSimon Blackwell <syblackwell@anywhichway.com>
Date2016-03-14 06:00 -0700
Message-ID<6c6a46ec-67b7-4436-b23a-c53c95adfe54@googlegroups.com>
In reply to#29888
On Friday, March 11, 2016 at 3:16:26 AM UTC-5, jonas.t...@gmail.com wrote:
> Den fredag 11 mars 2016 kl. 08:58:27 UTC+1 skrev jonas.t...@gmail.com:
> > function untangle_links(arr)
> > {
> >    printnode = new Array;
> >    var j = 0;
> >    var tempnode = 0;
> >    var tnode = new Array();
> >    for(var i = 0; i < nodes; i ++ )
> >    {
> >       for(var k = 0; k < tnode.length; k ++ )
> >       {
> >            if (arr[tempnode].nodelinks[j] == tnode[k])//Is this ok?
> >          {                                            //tnode[k] undefined or NaN?
> >             j ++ ;
> >          }
> >       }
> >       tempnode = arr[tempnode].nodelinks[j];
> >       tnode[tnode.length] = tempnode;
> >       printnode[i] = tempnode;
> >       j = 0;
> >    }
> >    return printnode;
> > }
> 
> I do not think i should need a special case to compare with null, undefined or NaN. But you never know. I mean if it isn't the same it isn't.

I think you will need:

arr[tempnode].nodelinks[j] == tnode[k] || (typeof(arr[tempnode].nodelinks[j])==="number" && typeof(tnode[k])==="number" && isNaN(
arr[tempnode].nodelinks[j]) && isNaN(tnode[k]))

According to the JavaScript spec a NaN does not equal a NaN, probably because they could represent different irrational numbers. Regardless, isNaN provides a way to check.

[toc] | [prev] | [standalone]


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


csiph-web