Post History
JavaScript (Node.js), 67 60 bytes o=>r=>Buffer(o).map(c=>c%32<26&c>64?(c%32+r)%26+c-c%32:c)+'' Try it online! o=>r=> // Define a function taking o an...
#2: Post edited
# [JavaScript (Node.js)], 67 bytes- <!-- language-all: lang-javascript -->
o=>r=>(b=Buffer)(b(o).map(c=>c%32<26&c>64?(c%32+r)%26+c-c%32:c))+''[Try it online!][TIO-krnf2y5z]- [JavaScript (Node.js)]: https://nodejs.org
[TIO-krnf2y5z]: https://tio.run/##FcfBDoIwDADQX/GCa7NA4jA7GDsST575g1GG0VRKBurnz/Bu7xW/ceX8XLZ61jGVnopSyBRgoNtnmlJGGECxeccFmAJXrbs6f@Tgzx3ssxkr5y3Xey6MaI0prPOqkhrRB/Rg7klEDz/NMhqEU4tY/g "JavaScript (Node.js) – Try It Online"- ```
o=>r=>( // Define a function taking o and rb = Buffer // Assign b to Buffer)( // And call on...b(o).map(c=> // a Buffer of the charcodes of o, mapped to...- c%32<26&c>64 // If the character is alphabetical - charcode%32 is less than 26, charcode is >64
- ? // Then
- (c%32+r)%26+c-c%32 // Rot-n the character - Mod 32, add r, mod 26, add correct number depending on whether it's uppercase of lowercase.
- :c) // Else return the original string
- ) + '' // Coerce to string
```
- # [JavaScript (Node.js)], <s>67</s> 60 bytes
- <!-- language-all: lang-javascript -->
- o=>r=>Buffer(o).map(c=>c%32<26&c>64?(c%32+r)%26+c-c%32:c)+''
- [Try it online!][TIO-ks11i9h2]
- [JavaScript (Node.js)]: https://nodejs.org
- [TIO-ks11i9h2]: https://tio.run/##FcfBDoIwDADQX/GCa7NAwiA7GDcTT5z5g6UMo6mUFJXPn@Hd3iv90kb6XD/1IlMuYygSooZ4/85zVhBs3mkFCpGqzl2dP1P0/Q2OWcXKeUv1kQuhNaaQLJtwblgeMIIZMrOcdlGeDELbIZY/ "JavaScript (Node.js) – Try It Online"
- ```
- o=>r=> // Define a function taking o and r, and returning...
- Buffer(o).map(c=> // a Buffer of the charcodes of o, mapped to...
- c%32<26&c>64 // If the character is alphabetical - charcode%32 is less than 26, charcode is >64
- ? // Then
- (c%32+r)%26+c-c%32 // Rot-n the character - Mod 32, add r, mod 26, add correct number depending on whether it's uppercase of lowercase.
- :c) // Else return the original string
- ) + '' // Coerce to string
- ```
- -7 thanks to Shaggy.
#1: Initial revision
# [JavaScript (Node.js)], 67 bytes
<!-- language-all: lang-javascript -->
o=>r=>(b=Buffer)(b(o).map(c=>c%32<26&c>64?(c%32+r)%26+c-c%32:c))+''
[Try it online!][TIO-krnf2y5z]
[JavaScript (Node.js)]: https://nodejs.org
[TIO-krnf2y5z]: https://tio.run/##FcfBDoIwDADQX/GCa7NA4jA7GDsST575g1GG0VRKBurnz/Bu7xW/ceX8XLZ61jGVnopSyBRgoNtnmlJGGECxeccFmAJXrbs6f@Tgzx3ssxkr5y3Xey6MaI0prPOqkhrRB/Rg7klEDz/NMhqEU4tY/g "JavaScript (Node.js) – Try It Online"
```
o=>r=>( // Define a function taking o and r
b = Buffer // Assign b to Buffer
)( // And call on...
b(o).map(c=> // a Buffer of the charcodes of o, mapped to...
c%32<26&c>64 // If the character is alphabetical - charcode%32 is less than 26, charcode is >64
? // Then
(c%32+r)%26+c-c%32 // Rot-n the character - Mod 32, add r, mod 26, add correct number depending on whether it's uppercase of lowercase.
:c) // Else return the original string
) + '' // Coerce to string
```
