Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news2.arglkargh.de!news.mixmin.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: "Christoph M. Becker" Newsgroups: comp.lang.javascript Subject: Re: function to get frequencies of a char array Date: Tue, 27 Jan 2015 19:35:20 +0100 Organization: solani.org Lines: 31 Message-ID: References: <26839541.MRbOrngyXZ@PointedEars.de> <87twzgl0aq.fsf@bsb.me.uk> <2697158.aGRKFDBAEn@PointedEars.de> <10619254.HIfIgzSeSj@PointedEars.de> <4289181.7vYxkYjVZ3@PointedEars.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: solani.org 1422383714 24570 eJwFwQcBACAIBMBKrGfEEZT+EbyDOvuEOdywWKbJDJymfFi1uDUTooWeqiW5SYxmlbP11D4RqBCq (27 Jan 2015 18:35:14 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Tue, 27 Jan 2015 18:35:14 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 X-User-ID: eJwFwQkBwDAIA0BLLW8iB1jxL2F3rnFj0sLDfH0P6PvQfMPz+lOxO6tA+UIjUqS5NRwUhfkDIaIRKA== In-Reply-To: <4289181.7vYxkYjVZ3@PointedEars.de> Cancel-Lock: sha1:Au9CBIv79Od920IN6u/hogMTfc0= X-NNTP-Posting-Host: eJwFwYEBwCAIA7CXUKEd5yDS/09YEgcLTUfAQyE97ptvbllWsSs6Kfg3ayOJI9HarNUx9PkBNqsR0g== Xref: csiph.com comp.lang.javascript:26733 Thomas 'PointedEars' Lahn wrote: > Christoph M. Becker wrote: > >> As we were talking about array *indexes*[1], values equal to or beyond >> 2³² are irrelevant, anyway. >> >> [1] > > I do not follow. In > > | if (e) { counts[e] ? ++counts[e] : (counts[e] = 1); } > > as cited, “e” is not an array index. To avoid the necessity to look up your code sample, I'll post the corrected version : for (var i = 0, len = a.length; i < len; ++i) { /* NOTE: hasOwnProperty() may be required */ var e = a[i]; if (e) { counts[e] ? ++counts[e] : (counts[e] = 1); } } Indeed, `e` is no array index, but `i` is. Therefore the value of the properties of `count` is always less than 2³² (even though it could be greater than or equal to 2³¹). -- Christoph M. Becker