Created
May 13, 2017 08:41
-
-
Save eiglow/1b991b69b712c290eb4d2cb9e4d5df2b 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
var BCode = { | |
delimiter : " ", | |
b : "🅱️", // if this looks like "ð ±ï¸" then something fucked up with character encodings | |
// i use for loops in all of these instead of Array.forEach because it's much faster | |
enc : function(str) { | |
var arr = str.split(""); | |
var res = ""; | |
for (let i = 0; i < arr.length; i++) { | |
var val = arr[i].charCodeAt(0); | |
for (let j = 0; j < val; j++) {res += BCode.b}; | |
if ((arr.length - i) > 1) res += BCode.delimiter; // ensure the delimiter isn't added onto the end | |
} | |
return res; | |
}, | |
dec : function(str) { | |
var arr = str.split(BCode.delimiter); | |
var res = ""; | |
for (let i = 0; i < arr.length; i++) { | |
var n = arr[i].length; | |
res += String.fromCharCode(n / 3); // WHY THE FUCK DO I NEED TO DIVIDE BY 3 | |
} | |
return res; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment