Z32814

{
    "Z1K1": "Z2",
    "Z2K1": {
        "Z1K1": "Z6",
        "Z6K1": "Z32814"
    },
    "Z2K2": {
        "Z1K1": "Z14",
        "Z14K1": "Z32780",
        "Z14K3": {
            "Z1K1": "Z16",
            "Z16K1": "Z600",
            "Z16K2": "function Z32780(Z32780K1, Z32780K2) {\n  const blocks_one = [\"\", \"tisíc\", \"milion\", \"miliarda\", \"bilion\", \"biliarda\", \"trilion\", \"triliarda\", \"kvadrilion\", \"kvadriliarda\", \"kvintilion\", \"kvintiliarda\", \"sextilion\", \"sextiliarda\", \"septilion\", \"septiliarda\"];\n  const blocks_few = [\"\", \"tisíce\", \"miliony\", \"miliardy\", \"biliony\", \"biliardy\", \"triliony\", \"triliardy\", \"kvadriliony\", \"kvadriliardy\", \"kvintiliony\", \"kvintiliardy\", \"sextiliony\", \"sextiliardy\", \"septiliony\", \"septiliardy\"];\n  const blocks_other = [\"\", \"tisíc\", \"milionů\", \"miliard\", \"bilionů\", \"biliard\", \"trilionů\", \"triliard\", \"kvadrilionů\", \"kvadriliard\", \"kvintilionů\", \"kvintiliard\", \"sextilionů\", \"sextiliard\", \"septilionů\", \"septiliard\"];\n  const unit_numerals = [\"\", \"\", \"\", \"tři\", \"čtyři\", \"pět\", \"šest\", \"sedm\", \"osm\", \"devět\"];\n\n\tfunction qid_from_enum (v) {\n\t\tlet type=v.Z1K1;\n\t\twhile (type.Z9K1){\n\t\t\ttype=type.Z9K1;\n\t\t}\n\t\tlet value=v[type+'K1'];\n\t\twhile (value.Z9K1){\n\t\t\tvalue=value.Z9K1;\n\t\t}\n\t\tlet typeOfValue=v[type+'K1'].Z1K1;\n\t\twhile(typeOfValue.Z9K1){\n\t\t\ttypeOfValue=typeOfValue.Z9K1;\n\t\t}\n\t\tvalue=value[typeOfValue+'K1'];\n\t\treturn value;\n\t}  \n\n  function gender_from_enum(v) {\n    switch(qid_from_enum(v)) {\n      case 'Q499327': return 'm';\n      case 'Q1775415': return 'f';\n      case 'Q1775461': return 'n';\n      default: Wikifunctions.Error(\"Z516\", [\"Z32780K2\", v]);\n    }\n  }\n\n  function space(word) {\n    return word.length ? \" \" + word : \"\";\n  }\n\n  function plural(x, one, few, other) {\n    if (x === 1) return one;\n    if (x \u003E= 2 \u0026\u0026 x \u003C= 4) return few;\n    return other;\n  }\n\n  function units(x, gender, is_many) {\n    if (x === 0) return \"\";\n\n    const one_genders = { \"m\": \"jeden\", \"f\": \"jedna\", \"n\": \"jedno\" };\n    const two_genders = { \"m\": \"dva\", \"f\": \"dvě\", \"n\": \"dvě\" };\n\n    if (is_many) {\n      switch (x) {\n        case 1:\n          return \"jedna\";\n        case 2:\n          return \"dva\";\n        default:\n          return unit_numerals[x];\n      }\n    } else {\n      switch (x) {\n        case 1:\n          return one_genders[gender];\n        case 2:\n          return two_genders[gender];\n        default:\n          return unit_numerals[x];\n      }\n    }\n  }\n\n  function tens(x, gender, is_many) {\n    const teens = [\"deset\", \"jedenáct\", \"dvanáct\", \"třináct\", \"čtrnáct\", \"patnáct\", \"šestnáct\", \"sedmnáct\", \"osmnáct\", \"devatenáct\"];\n    const tens_words = [\"\", \"deset\", \"dvacet\", \"třicet\", \"čtyřicet\", \"padesát\", \"šedesát\", \"sedmdesát\", \"osmdesát\", \"devadesát\"]\n\n    const tens = Math.trunc(x / 10);\n    switch (tens) {\n      case 0:\n        return units(x, gender, is_many);\n      case 1:\n        return teens[x - 10];\n      default:\n        return tens_words[tens] + space(units(x % 10, gender, true));\n    }\n  }\n\n  function hundreds(x, gender, is_many) {\n    const hundreds = Math.trunc(x / 100);\n    if (hundreds === 0) return tens(x, gender, is_many);\n\n    var hundreds_text;\n    switch (hundreds) {\n      case 1:\n        hundreds_text = \"sto\";\n        break;\n      case 2:\n        hundreds_text = \"dvě stě\";\n        break;\n      case 3:\n        hundreds_text = \"tři sta\";\n        break;\n      case 4:\n        hundreds_text = \"čtyři sta\";\n        break;\n      default:\n        hundreds_text = unit_numerals[hundreds] + \" set\";\n    }\n\n    return hundreds_text + space(tens(x % 100, gender, true));\n  }\n\n  function block(x, block_one, block_few, block_other, gender, is_many) {\n    const numeral = hundreds(x, gender, is_many);\n    if (!numeral.length) return \"\";\n\n    const block_name = plural(x, block_one, block_few, block_other);\n\n    return numeral + space(block_name);\n  }\n\n  let value = Z32780K1;\n  let gender = gender_from_enum(Z32780K2);\n\n  if (value == 0n) { return \"nula\"; }\n  if (value \u003E 999999999999999999999999999999999999999999999999n) { Wikifunctions.Error(\"Z28307\", [\"\" + value, \"999999999999999999999999999999999999999999999999\", \"cs\"]); }\n\n  const blocks = [];\n  let is_greater_than_one = value \u003E 1n;\n  let last_is_one = false;\n  for (let i = 0; i \u003C blocks_one.length \u0026\u0026 value \u003E 0n; ++i) {\n    const block_value = Number(value % 1000n);\n    last_is_one = block_value === 1;\n    value /= 1000n;\n\n    let block_gender;\n    if (i === 0) block_gender = gender;\n    else if (i === 1 || (i % 2) === 0) block_gender = \"m\";\n    else block_gender = \"f\";\n    const text = block(block_value, blocks_one[i], blocks_few[i], blocks_other[i], block_gender, i === 0 \u0026\u0026 value \u003E 0n);\n    if (text.length) blocks.push(text);\n  }\n\n  // drop leading “one” (but it’s a matter of taste)\n  if (is_greater_than_one \u0026\u0026 last_is_one) blocks[blocks.length - 1] = blocks[blocks.length - 1].substring(5).trimStart();\n\n  return blocks.reverse().join(\" \");\n}"
        }
    },
    "Z2K3": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11",
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1062",
                "Z11K2": "JavaScriptová implementace české základní číslovky"
            },
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1002",
                "Z11K2": "JavaScript implementation of Czech cardinal"
            }
        ]
    },
    "Z2K4": {
        "Z1K1": "Z32",
        "Z32K1": [
            "Z31"
        ]
    },
    "Z2K5": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11"
        ]
    }
}