• Re: Nth (Ordinal Numeral Suffix)

    From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.lang.awk on Tue Nov 7 14:17:59 2023
    From Newsgroup: comp.lang.awk

    On 06.11.2023 13:54, Ed Morton wrote:
    On 11/5/2023 1:04 PM, Janis Papanagnou wrote:

    Fast pre-calculated solutions can also be legible.

    Apparently we just have different ideas of legible

    (This makes no sense; given what I said here and what you say below.)

    The advantage of the pattern approach is, though, that it matches
    exactly the specification/definition[*], as the cases are typically
    explained. - But I think it's boring to talk on that "ideas" level.

    - to me a hash lookup
    is the clear and obvious way to implement this rather than a bunch of
    if/else regexp comparisons.

    Taking the idea of your variant further can simplify it even, e.g.

    function nth_pre (num)
    {
    if (num ~ /[^0-9]/) return num
    return num e[num%100]
    }
    [...]

    That's a very good idea. [...]

    Yes, it's simple and legible. - No unnecessary 'if' cases and no hash
    arrays ("huns" and "tens") that introduce unnecessary complexity
    where you need only a single and clear mapping of the relevant digits.

    Janis

    [*] See for example https://en.wikipedia.org/wiki/Ordinal_suffix

    --- Synchronet 3.20a-Linux NewsLink 1.114