Jump to content

en international morse code encode in JavaScript Z10968
en Implementation

ຈາກ Wikifunctions
use non-BMP aware function to split characters
turn the map into a simpler json, just that I personally it's a simpler implementation and it's advantage would be we can store the data separately from the function in future but if you disagree feel free to just revert my edit
ແຖວ ໑໔: ແຖວ ໑໔:
"Z61K1": "javascript"
"Z61K1": "javascript"
},
},
"Z16K2": "function Z10944( Z10944K1 ) {\n\tconst MORSE_MAP = new Map([\n\t\t[\"a\", \".-\"],\n\t\t[\"b\", \"-...\"],\n\t\t[\"c\", \"-.-.\"],\n\t\t[\"d\", \"-..\"],\n\t\t[\"e\", \".\"],\n\t\t[\"é\", \"..-..\"],\n\t\t[\"f\", \"..-.\"],\n\t\t[\"g\", \"--.\"],\n\t\t[\"h\", \"....\"],\n\t\t[\"i\", \"..\"],\n\t\t[\"j\", \".---\"],\n\t\t[\"k\", \"-.-\"],\n\t\t[\"l\", \".-..\"],\n\t\t[\"m\", \"--\"],\n\t\t[\"n\", \"-.\"],\n\t\t[\"o\", \"---\"],\n\t\t[\"p\", \".--.\"],\n\t\t[\"q\", \"--.-\"],\n\t\t[\"r\", \".-.\"],\n\t\t[\"s\", \"...\"],\n\t\t[\"t\", \"-\"],\n\t\t[\"u\", \"..-\"],\n\t\t[\"v\", \"...-\"],\n\t\t[\"w\", \".--\"],\n\t\t[\"x\", \"-..-\"],\n\t\t[\"y\", \"-.--\"],\n\t\t[\"z\", \"--..\"],\n\t\t[\"1\", \".----\"],\n\t\t[\"2\", \"..---\"],\n\t\t[\"3\", \"...--\"],\n\t\t[\"4\", \"....-\"],\n\t\t[\"5\", \".....\"],\n\t\t[\"6\", \"-....\"],\n\t\t[\"7\", \"--...\"],\n\t\t[\"8\", \"---..\"],\n\t\t[\"9\", \"----.\"],\n\t\t[\"0\", \"-----\"],\n\t\t[\".\", \".-.-.-\"],\n\t\t[\",\", \"--..--\"],\n\t\t[\":\", \"---...\"],\n\t\t[\"?\", \"..--..\"],\n\t\t[\"'\", \".----.\"],\n\t\t[\"-\", \"-....-\"],\n\t\t[\"–\", \"-....-\"],\n\t\t[\"—\", \"-....-\"],\n\t\t[\"/\", \"-..-.\"],\n\t\t[\"(\", \"-.--.\"],\n\t\t[\")\", \"-.--.-\"],\n\t\t[\"\\\"\", \".-..-.\"],\n\t\t[\"“\", \".-..-.\"],\n\t\t[\"”\", \".-..-.\"],\n\t\t[\"=\", \"-...-\"],\n\t\t[\"+\", \".-.-.\"],\n\t\t[\"×\", \"-..-\"],\n\t\t[\"@\", \".--.-.\"],\n\t\t[\" \", \"/\"],\n\t]);\n\t\n\tconst inStr = Z10944K1.trim()\n\t\t.toLowerCase()\n\t\t.replace(/\\s+/g, \" \");\n\t\n\treturn [...inStr]\n\t\t.filter((c) =\u003E MORSE_MAP.has(c))\n\t\t.map((c) =\u003E MORSE_MAP.get(c))\n\t\t.join(\" \");\n}"
"Z16K2": "function Z10944( Z10944K1 ) {\n\tconst MORSE_MAP = {\n\t\t\"a\": \".-\",\n\t\t\"b\": \"-...\",\n\t\t\"c\": \"-.-.\",\n\t\t\"d\": \"-..\",\n\t\t\"e\": \".\",\n\t\t\"é\": \"..-..\",\n\t\t\"f\": \"..-.\",\n\t\t\"g\": \"--.\",\n\t\t\"h\": \"....\",\n\t\t\"i\": \"..\",\n\t\t\"j\": \".---\",\n\t\t\"k\": \"-.-\",\n\t\t\"l\": \".-..\",\n\t\t\"m\": \"--\",\n\t\t\"n\": \"-.\",\n\t\t\"o\": \"---\",\n\t\t\"p\": \".--.\",\n\t\t\"q\": \"--.-\",\n\t\t\"r\": \".-.\",\n\t\t\"s\": \"...\",\n\t\t\"t\": \"-\",\n\t\t\"u\": \"..-\",\n\t\t\"v\": \"...-\",\n\t\t\"w\": \".--\",\n\t\t\"x\": \"-..-\",\n\t\t\"y\": \"-.--\",\n\t\t\"z\": \"--..\",\n\t\t\"1\": \".----\",\n\t\t\"2\": \"..---\",\n\t\t\"3\": \"...--\",\n\t\t\"4\": \"....-\",\n\t\t\"5\": \".....\",\n\t\t\"6\": \"-....\",\n\t\t\"7\": \"--...\",\n\t\t\"8\": \"---..\",\n\t\t\"9\": \"----.\",\n\t\t\"0\": \"-----\",\n\t\t\".\": \".-.-.-\",\n\t\t\",\": \"--..--\",\n\t\t\":\": \"---...\",\n\t\t\"?\": \"..--..\",\n\t\t\"'\": \".----.\",\n\t\t\"-\": \"-....-\",\n\t\t\"–\": \"-....-\",\n\t\t\"—\": \"-....-\",\n\t\t\"/\": \"-..-.\",\n\t\t\"(\": \"-.--.\",\n\t\t\")\": \"-.--.-\",\n\t\t\"\\\"\": \".-..-.\",\n\t\t\"“\": \".-..-.\",\n\t\t\"”\": \".-..-.\",\n\t\t\"=\": \"-...-\",\n\t\t\"+\": \".-.-.\",\n\t\t\"×\": \"-..-\",\n\t\t\"@\": \".--.-.\",\n\t\t\" \": \"/\",\n\t};\n\t\n\tconst inStr = Z10944K1.trim()\n\t\t.toLowerCase()\n\t\t.replace(/\\s+/g, \" \");\n\t\n\treturn [...inStr]\n\t\t.filter(c =\u003E Object.hasOwn(MORSE_MAP, c))\n\t\t.map(c =\u003E MORSE_MAP[c])\n\t\t.join(\" \");\n}"
}
}
},
},

ລຸ້ນແກ້ໄຂເກົ່າເມື່ອ ໐໙:໓໑, ໓໑ ສິງຫາ ໒໐໒໓

This page displays in a limited way without JavaScript.