Skip to content

Instantly share code, notes, and snippets.

@alacret
Created February 25, 2020 01:27
Show Gist options
  • Save alacret/bd518dae45cc3b66e7803f9798cc31d5 to your computer and use it in GitHub Desktop.
Save alacret/bd518dae45cc3b66e7803f9798cc31d5 to your computer and use it in GitHub Desktop.
const S = {
TAB : "\t",
SPACE : " ",
BREAK : "\n",
}
// S.TAB = "[tab]";
// S.SPACE = "[space]";
// S.BREAK = "[LF]";
function whitespaceNumber(n) {
if (n === 0)
return " \n";
const result = [];
if (n > 0)
result.push(S.SPACE);
else
result.push(S.TAB);
const absNumber = Math.abs(n);
const binaryNumber = absNumber.toString(2);
binaryNumber.split('').forEach(n => {
if (n === '0') result.push(S.SPACE)
else result.push(S.TAB)
})
result.push(S.BREAK);
return result.join('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment