Path: csiph.com!usenet.pasdenom.info!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: Sat, 24 Jan 2015 18:05:49 +0100 Organization: solani.org Lines: 20 Message-ID: References: <26839541.MRbOrngyXZ@PointedEars.de> <87twzgl0aq.fsf@bsb.me.uk> <2697158.aGRKFDBAEn@PointedEars.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: solani.org 1422119138 5776 eJwNxckVADAEBcCWLB9POUj0X0IylzF19gm4OWxtM5u1WumS9GSMBcYluAnnFiihskCiqP4PEjYQkA== (24 Jan 2015 17:05:38 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Sat, 24 Jan 2015 17:05:38 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 X-User-ID: eJwFwQkBACAIA8BKKownDoLrH8E7iG1rV4MpCCqvxJMYFcxQvFb0PX6wmFWRO1qDABQvnR8eWBDv In-Reply-To: Cancel-Lock: sha1:d7OF5eFCXHHMh9SPkpOBt/efDGQ= X-NNTP-Posting-Host: eJwFwQEBACAIA7BMCBys8wv9I7ilw6AKJCI3t2ZRAkfOOJgRrWv5GG4Hq6B3XEto7d3+NXwRoQ== Xref: csiph.com comp.lang.javascript:26692 Evertjan. wrote: > Thomas 'PointedEars' Lahn wrote on 24 jan 2015 in > comp.lang.javascript: > >> No, but >> >> if (e) { counts[e] ? ++counts[e] : (counts[e] = 1); } > > if (e) counts[e] = (counts[e]|0) + 1; That has slightly different semantics, which probably won't matter in practise, though. Nonetheless I would prefer the following (if I'd use a shortcut at all): if (e) counts[e] = (counts[e] || 0) + 1; -- Christoph M. Becker