Created
March 4, 2023 23:59
-
-
Save razzius/511efee068140931bc24bb01ce81eaa6 to your computer and use it in GitHub Desktop.
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
const space = String.fromCharCode(32) | |
const at_symbol = String.fromCharCode(64) | |
const newline = String.fromCharCode(10) | |
const openb = String.fromCharCode(91) | |
const closb = String.fromCharCode(93) | |
const quote = String.fromCharCode(39) | |
const comma = String.fromCharCode(44) | |
function represent(ss) { | |
return ss.join(newline).replace( | |
at_symbol, | |
openb + newline + ss.map(function(s) { | |
return space + space + quote + s + quote | |
}).join(comma + newline) + newline + closb | |
) | |
} | |
const ss = [ | |
'const space = String.fromCharCode(32)', | |
'const at_symbol = String.fromCharCode(64)', | |
'const newline = String.fromCharCode(10)', | |
'const openb = String.fromCharCode(91)', | |
'const closb = String.fromCharCode(93)', | |
'const quote = String.fromCharCode(39)', | |
'const comma = String.fromCharCode(44)', | |
'function represent(ss) {', | |
' return ss.join(newline).replace(', | |
' at_symbol,', | |
' openb + newline + ss.map(function(s) {', | |
' return space + space + quote + s + quote', | |
' }).join(comma + newline) + newline + closb', | |
' )', | |
'}', | |
'const ss = @', | |
'console.log(represent(ss))' | |
] | |
console.log(represent(ss)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment