On Tuesday, 30 May 2017 at 10:54:49 UTC, Solomon E wrote:

The earlier version of the page made D look more error prone than other languages, but short. Now my solution is as long as some of the other language's solutions, but it's well commented and tested, I think. Now I doubt any of the solutions in other languages are as correct or potentially useful or informative.


Regardless to solution length...one place to make code a little shorter could be when you check for special prefix; maybe replace the two foreach loops? Something like:

if (specials != null) {
// There may be special prefixed formats that use different separators. // Any format with a longer prefix should override a shorter one.
    auto pairs = specials.byKeyValue
                         .array
.sort!((a,b) => a.key.length < b.key.length);

    auto preAnyDigit = matchNum.pre.stripRight('0');

    pairs.filter!(a => preAnyDigit.length >= a.key.length)
.filter!(a => a.key == preAnyDigit[$ - a.key.length .. $])
         .each!(a => ins = a.value);
}

Jordan

Reply via email to