Skip to main content
golfed 3 bytes
Source Link
ETHproductions
  • 50.1k
  • 6
  • 94
  • 240

JavaScript (ES6), 5252 49 bytes

s=>s.replacef=s=>s&&(/s./g,s=>charCodeAt()+4+f(s.charCodeAtslice(1)+4+"")).slice(1))

Recursion seemsturned out to be 23 bytes longer in 2 different waysshorter than .replace:

f=([c,...s])=>c?(cs=>s.charCodeAtreplace()+4+"")/.slice(1)+f(s):""
f=s=>s?/g,s=>(s.charCodeAt()+4+"").slice(1)+f(s.slice(1)):""

parseInt(s,36) is 1-4 bytesslightly longer for each approach, because you have to change 4 to 91:

s=>s.replace(/./g,s=>(s.charCodeAt()+4+"").slice(1))
f=([c,...s])=>c?(parseInt(cs,36)+91+"").slice(1)+f(s):""
f=s=>s?f=s=>s&&(parseInt(s[0],36)+91+"")+91+f(s.slice(1)+f(s)).slice(1)):""

JavaScript (ES6), 52 bytes

s=>s.replace(/./g,s=>(s.charCodeAt()+4+"").slice(1))

Recursion seems to be 2 bytes longer in 2 different ways:

f=([c,...s])=>c?(c.charCodeAt()+4+"").slice(1)+f(s):""
f=s=>s?(s.charCodeAt()+4+"").slice(1)+f(s.slice(1)):""

parseInt(s,36) is 1-4 bytes longer for each approach, because you have to change 4 to 91:

s=>s.replace(/./g,s=>(s.charCodeAt()+4+"").slice(1))
f=([c,...s])=>c?(parseInt(c,36)+91+"").slice(1)+f(s):""
f=s=>s?(parseInt(s[0],36)+91+"").slice(1)+f(s.slice(1)):""

JavaScript (ES6), 52 49 bytes

f=s=>s&&(s.charCodeAt()+4+f(s.slice(1))).slice(1)

Recursion turned out to be 3 bytes shorter than .replace:

s=>s.replace(/./g,s=>(s.charCodeAt()+4+"").slice(1))

parseInt(s,36) is slightly longer for each approach, because you have to change 4 to 91:

s=>s.replace(/./g,s=>(parseInt(s,36)+91+"").slice(1))
f=s=>s&&(parseInt(s[0],36)+91+f(s.slice(1))).slice(1)
Source Link
ETHproductions
  • 50.1k
  • 6
  • 94
  • 240

JavaScript (ES6), 52 bytes

s=>s.replace(/./g,s=>(s.charCodeAt()+4+"").slice(1))

Recursion seems to be 2 bytes longer in 2 different ways:

f=([c,...s])=>c?(c.charCodeAt()+4+"").slice(1)+f(s):""
f=s=>s?(s.charCodeAt()+4+"").slice(1)+f(s.slice(1)):""

parseInt(s,36) is 1-4 bytes longer for each approach, because you have to change 4 to 91:

s=>s.replace(/./g,s=>(s.charCodeAt()+4+"").slice(1))
f=([c,...s])=>c?(parseInt(c,36)+91+"").slice(1)+f(s):""
f=s=>s?(parseInt(s[0],36)+91+"").slice(1)+f(s.slice(1)):""