Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <23946178.EFlsh5Ejh5@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Fri, 20 Dec 2013 22:29:08 +0100 User-Agent: KNode/4.11.3 Content-Transfer-Encoding: 8Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. <5f4va916l0r2qoto1r4iq5dh0i0dnqthnv@hive.bjoern.hoehrmann.de> <3082498.rgpu3afg7L@PointedEars.de> MIME-Version: 1.0 Lines: 87 NNTP-Posting-Date: 20 Dec 2013 22:29:11 CET NNTP-Posting-Host: 90ce7eda.newsspool1.arcor-online.net X-Trace: DXC=UhO3aWE;<9o^Y=RbYBPl4`ic==]BZ:afn4Fo<]lROoRankgeX?EC@@`0E8X5N4L0EbDZm8W4\YJNlYUVHKH;GI^g3i]3M\eAI?h1en]MhNnB6h X-Complaints-To: usenet-abuse@arcor.de Xref: csiph.com comp.lang.javascript:22371 Thomas 'PointedEars' Lahn wrote: > Bjoern Hoehrmann wrote: >> A simple solution would be to use a Regex to split the value into its >> components and converting into a form like `yyyymmdd`. You can then use >> string comparison to find the minimum and maximum value (you could sort >> the values but that has non-linear worst case behavior). In Perl, >> >> my ($m, $d, $y) = m#(\S+)\s+(\d+)/(\d+)#; >> $m = { >> Jan => 1, >> Feb => 2, >> ... >> }->{$m}; >> >> my $comparable = sprintf "%04u%02u%02u", $y, $m, $d; >> >> […] > > In JavaScript 1.5 and later, as in other implementations of ECMAScript Edition _3_ and later, > you can do much the same as in Perl: > > […] > /* > * or > > var m = ({ > "Jan": 1, > "Feb": 2, > … > })[matches.groups["m"]]; > > * with JSX:regexp.js [2] > */ > var m = ({ > "Jan": 1, > "Feb": 2, > … > })[matches[0]]; var m = { "Jan": 1, "Feb": 2, … }[matches[0]]; (and similar; without parentheses) suffices because the right-hand side of the assignment is evaluated in Expression context, not Statement context. This is different with var s = '{"foo": "bar"}'; /* Syntax error in the /Program/ parsed by eval() */ var o = eval(s): /* Correct syntax in the /Program/ parsed by eval() */ var o = eval("(" + s + ")"): – as an insecure but backwards-compatible stand-in for JSON.parse() – and when for some reason you want to access a specific object referred by another object's property, based on a name: var s = "foo"; { "foo": ["baz", "bar"] }[s].sort(); is a Syntax error; var s = "foo"; ({ "foo": ["baz", "bar"] })[s].sort(); is not. -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail.