JS coding style example. codepoint to utf16 encoding
supreme js fp functional programing
/* xah_codepoint_to_utf16_hexStr(zcodepoint) return a string of hexadecimal that's the UTF-16 encoding of the char of codepoint zcodepoint (integer). */ // before const xah_codepoint_to_utf16_hexStr = (zcodepoint) => { const xCharStr = String.fromCodePoint(zcodepoint); if (zcodepoint < 2 ** 16) { return xCharStr.charCodeAt(0).toString(16).toUpperCase(); } else { const xout = []; for (let i = 0; i < xCharStr.length; i++) { xout.push(xCharStr.charCodeAt(i).toString(16).toUpperCase()); } return xout.join(" "); } }; // after const xah_codepoint_to_utf16_hexStr = (zcodepoint) => ((xstr) => (Array.from(Array(xstr.length).keys(), (x) => (xstr.charCodeAt(x).toString(16).toUpperCase())).join(" ")))(String.fromCodePoint(zcodepoint));
actually the 2 versions are not semantically the same. but the latter is a improvement anyhow.
it is shown here to as code study example.