Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: How to manipulate integer that sometimes Nan and sometimes have a value? Date: Sat, 26 Sep 2015 20:51:33 +0100 Organization: A noiseless patient Spider Lines: 45 Message-ID: <87fv21dkmy.fsf@bsb.me.uk> References: <9060ce04-2f9e-4554-be83-2f69c213424f@googlegroups.com> <4f31ec16-109f-43b2-9d50-b39d4fb47f84@googlegroups.com> <3cf46737-de54-489e-9d9d-89413b18c099@googlegroups.com> <87wpvdec2d.fsf@bsb.me.uk> <64092fce-7ef7-48d7-9e0d-27a2220fcfe0@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="24439"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18b5Yvmt0WhtzYQwVidKAt3Gmr83M+dRkY=" Cancel-Lock: sha1:1VHVSD0fpd7vWnK3yj42F7Rj93s= sha1:DsxQveM2EacvhC66Fb0opwMBzJs= X-BSB-Auth: 1.5967c242c2ebdf77ec2b.20150926205133BST.87fv21dkmy.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:28736 jonas.thornvall@gmail.com writes: > Den lördag 26 september 2015 kl. 11:59:23 UTC+2 skrev Ben Bacarisse: >> jonas.thornvall@gmail.com writes: >> >> > 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. >> >> As yet unassigned positions in an array are undefined but the isNaN >> function returned true for undefined values. It's likely that you don't >> have a numeric NaN in addOne[i], but undefined instead. >> > > Yes that is the problem Ben when you use array elements as digits > places. If it is an add operation that will carry extra digit you will > add to an index where the element may be a NaN value. You say "yes" but I don't think you got what I said. An as yet unassigned array position is undefined -- it won't have NaN as its value. However, isNaN (the global function by that name) converts it's argument in such a way that undefined becomes NaN. $ nodejs > var a = []; undefined > a[1] undefined > a[1] === undefined true > isNaN(a[1]) This may be why you think you have NaN in the "extra" digit places. -- Ben.