Last active
June 9, 2018 00:27
-
-
Save friendlyanon/fd04601ca277c43d79ed4e3a10d4cbca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function* shrinkGen(s) { | |
let i = -1, c; | |
while (c = s.charCodeAt(++i)) yield c << 0 | (s.charCodeAt(++i) || 0) << 8; | |
} | |
function shrink(input) { | |
return String.fromCodePoint(...shrinkGen(input)); | |
} | |
function* expandGen(str) { | |
let i = -1, c; | |
while (c = str.codePointAt(++i)) { | |
yield c & 0x00FF; | |
const high = (c & 0xFF00) >> 8; | |
if (high) yield high; | |
} | |
} | |
function expand(input) { | |
return String.fromCharCode(...expandGen(input)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment