Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!ecngs!feeder2.ecngs.de!46.4.82.166.MISMATCH!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: function to get frequencies of a char array Date: Tue, 27 Jan 2015 14:50:58 +0100 Organization: PointedEars Software (PES) Lines: 61 Message-ID: <4289181.7vYxkYjVZ3@PointedEars.de> References: <26839541.MRbOrngyXZ@PointedEars.de> <87twzgl0aq.fsf@bsb.me.uk> <2697158.aGRKFDBAEn@PointedEars.de> <10619254.HIfIgzSeSj@PointedEars.de> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1422366698 25004 eJwFwYEBwDAEBMCVSD0yDi/2H6F3+FydYQ43LPbOGUoahBKeo01m6m083UZGHRT2ldGmRX8cURFa (27 Jan 2015 13:51:38 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Tue, 27 Jan 2015 13:51:38 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwFwYEBwDAEBMCVPnhiHKH2H6F3VD/eYU43LldutEzh8FhXMj60j5AtGtPQqxf2PGaQD4KVrd0UwzNm/Tp1FO8= Cancel-Lock: sha1:Trayui5FPfiSAqVCBNpgm/M+iC8= X-NNTP-Posting-Host: eJwVy7EBACEIBLCVALmTdQRk/xH8r1IFi8raTtAxGLecquiIs058LkwhRcXERtuvdTIv5Q+7HyZFESs= Xref: csiph.com comp.lang.javascript:26732 Christoph M. Becker wrote: > Thomas 'PointedEars' Lahn wrote: >> Christoph M. Becker wrote: >>> Evertjan. wrote: >>>> This was about a count, >>>> in Javascript you cannot >>>> in a single variable >>>> count from 0 to 1e32 >>>> for reasons of […] resolution. >>> >>> […] >>> However, I don't understand what you mean by "resolution". >> >> [limits of IEEE 754 doubles’ integer precision] > > Thanks for the explanation. You’re welcome. > Actually, I screwed up again, as I meant 2³² (not 10³²), which can be > represented exactly as integer, but doesn't "survive" the ToInt32() > call. Even 2³¹ does not: > > Math.pow(2, 31) | 0 // => -2147483648 Correct. I suspected something was wrong with using “| 0” there, but had not found the time to investigate it. Thanks. I have also stated that I would not use Array.prototype.reduce() to return a non-primitive value. It is possible that judgement was incorrect. It is rather fascinating to obtain a character (or word) statistics¹ of an HTML document (or any other text) – confirming, for example, that “e” usually is the most frequent letter –, just by typing document.body.textContent.split("").reduce(function (prev, curr) { prev[curr] = (prev[curr] || 0) + 1; return prev; }, Object.create(null)); as one line into the script console. ______ ¹ it is possible to split() using a regular expression like /\s+/ > 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. -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.