Skip to content

Instantly share code, notes, and snippets.

@eiglow
Created May 13, 2017 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eiglow/1b991b69b712c290eb4d2cb9e4d5df2b to your computer and use it in GitHub Desktop.
Save eiglow/1b991b69b712c290eb4d2cb9e4d5df2b to your computer and use it in GitHub Desktop.
🅱️code
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