Last active
July 8, 2018 00:05
-
-
Save Spuffynism/d48091f0d478712b83d366c89cfe67d2 to your computer and use it in GitHub Desktop.
Squeeze utf-8 characters in half their space
This file contains hidden or 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
| let squeeze = s => s.replace(/../g,c=>String.fromCharCode(c[a='charCodeAt']()|c[a](1)<<7)); | |
| let unsqueeze = s => s.replace(/./g,c=>String.fromCharCode((c=c.charCodeAt())&127,c>>7)); | |
| console.log(unsqueeze("㟦ᑲᝣ㓷㩤㹨㒽Ჽ㒻ᚭᒻ㓦㙬㋒㩣ᨨᠰ㒫ᢪᠰ⦫㨨ᔩᠳᘰᠴᘰᠵᠰᶩ") === | |
| "for(c.width|=i=9;i--;)x.fillRect(400+i*100+S(t)*300,400,50,200);"); | |
| console.log(squeeze("for(c.width|=i=9;i--;)x.fillRect(400+i*100+S(t)*300,400,50,200);") === | |
| "㟦ᑲᝣ㓷㩤㹨㒽Ჽ㒻ᚭᒻ㓦㙬㋒㩣ᨨᠰ㒫ᢪᠰ⦫㨨ᔩᠳᘰᠴᘰᠵᠰᶩ"); | |
| console.log("㟦ᑲᝣ㓷㩤㹨㒽Ჽ㒻ᚭᒻ㓦㙬㋒㩣ᨨᠰ㒫ᢪᠰ⦫㨨ᔩᠳᘰᠴᘰᠵᠰᶩ".length === 32); | |
| console.log("for(c.width|=i=9;i--;)x.fillRect(400+i*100+S(t)*300,400,50,200);".length === 64); | |
| // codegolf example | |
| eval("㟦ᑲᝣ㓷㩤㹨㒽Ჽ㒻ᚭᒻ㓦㙬㋒㩣ᨨᠰ㒫ᢪᠰ⦫㨨ᔩᠳᘰᠴᘰᠵᠰᶩ".replace(/./g,c=>String.fromCharCode((c=c.charCodeAt())&127,c>>7))) | |
| eval([..."㟦ᑲᝣ㓷㩤㹨㒽Ჽ㒻ᚭᒻ㓦㙬㋒㩣ᨨᠰ㒫ᢪᠰ⦫㨨ᔩᠳᘰᠴᘰᠵᠰᶩ"].map(c=>String.fromCharCode((c=c.charCodeAt())&127,c>>7)).join``) | |
| eval([].map.call("㟦ᑲᝣ㓷㩤㹨㒽Ჽ㒻ᚭᒻ㓦㙬㋒㩣ᨨᠰ㒫ᢪᠰ⦫㨨ᔩᠳᘰᠴᘰᠵᠰᶩ",c=>String.fromCharCode((c=c.charCodeAt())&127,c>>7)).join``) | |
| eval([..." 㟦ᑲᝣ㓷㩤㹨㒽Ჽ㒻ᚭᒻ㓦㙬㋒㩣ᨨᠰ㒫ᢪᠰ⦫㨨ᔩᠳᘰᠴᘰᠵᠰᶩ"].reduce((a,c)=>a+=String.fromCharCode((c=c.charCodeAt())&127,c>>7))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment