Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

66%
+2 −0
Challenges Caesar shift cipher

Javascript (V8), 202 97 bytes o=>r=>o.replace(/[a-zA-Z]/g,o=>String.fromCharCode((o<="Z"?90:122)>=(o=o.charCodeAt()+r)?o:o-26)) Try it online! Since the text of input must be ma...

posted 3y ago by Kevin M. Mansour‭  ·  edited 3y ago by Kevin M. Mansour‭

Answer
#5: Post edited by user avatar Kevin M. Mansour‭ · 2021-07-29T02:00:44Z (over 3 years ago)
Golfing..
  • # [Javascript (V8)](https://v8.dev/), 202 bytes
  • ```js
  • function rot(o,r){return o.replace(/[a-zA-Z]/g,function(o){return String.fromCharCode((o<="Z"?90:122)>=(o=o.charCodeAt(0)+r)?o:o-26)})}(function update(){const o=rot("Hello World",4);console.log(o)})();
  • ```
  • [Try it online!](https://tio.run/##Pc7NCoJAFIbhWxFX55BaSUR/FtGmfYugaDGMoxnTfHIaWxReuxVU6/ddPBd1VzctVe3j@6TrisZpX8EFAk@IhJ9ifCMuQCKmtkob6h9V/FjHh1O/jH474T/uvFSuTArBdXNWskFuiLDIwkO4mg5mwzTlZUbIkOhvXnsacE94hRnidMwtt/R3NHWuvCF@aribD5B9YOHWWItgD7F5GI14/omwJrEo35SWiedd9wI)
  • Since the text of input must be manually changed from the code, here is how to change it, Go to `const o=rot("Hello World",4);` and change the text between `""` (string) to something like `const o=rot("Codidact Code Golf",4);` or anything you like then run. also you can change ROT$n$ by changing number 4 in `const o=rot("Hello World",4);` to anything you like `const o=rot("Hello World",13);`.
  • # [Javascript (V8)](https://v8.dev/), <strike>202</strike> 97 bytes
  • ```js
  • o=>r=>o.replace(/[a-zA-Z]/g,o=>String.fromCharCode((o<="Z"?90:122)>=(o=o.charCodeAt()+r)?o:o-26))
  • ```
  • [Try it online!](https://tio.run/##Lc2xDoIwEADQX2k63UUpSoxRtBDC4u5ggnFoSkVM5cjRMPjzlcH5De9tZjNZ7seQzIfoXRBMQWgRSResC1LsRm@sg/Rukm@VNI@0Wy92DdwPnXoyfeqX4ZpaB0BnLRtZHjf5Nsuw0ECalP1zFQBXjCXllGR7xGhpmMg75amDJQV5cd6TuBH7ViLsEE/xBw)
  • Since the text of input must be manually changed from the code, here is how to change it, Go to `console.log(rot("Hello World")(4));` and change text between `""` (String) into anything you want lke `console.log(rot("Codidact Code Golf)(4));` and if you want to change ROT$n$, change the number between brackets into anything like `console.log(rot("Codidact Code Golf)(13));`.
#4: Post edited by user avatar Kevin M. Mansour‭ · 2021-07-28T11:17:39Z (over 3 years ago)
....
  • # [Javascript (V8)](https://v8.dev/), 202 bytes
  • ```js
  • function rot(o,r){return o.replace(/[a-zA-Z]/g,function(o){return String.fromCharCode((o<="Z"?90:122)>=(o=o.charCodeAt(0)+r)?o:o-26)})}(function update(){const o=rot("Hello World",4);console.log(o)})();
  • ```
  • [Try it online!](https://tio.run/##Pc7NCoJAFIbhWxFX55BaSUR/FtGmfYugaDGMoxnTfHIaWxReuxVU6/ddPBd1VzctVe3j@6TrisZpX8EFAk@IhJ9ifCMuQCKmtkob6h9V/FjHh1O/jH474T/uvFSuTArBdXNWskFuiLDIwkO4mg5mwzTlZUbIkOhvXnsacE94hRnidMwtt/R3NHWuvCF@aribD5B9YOHWWItgD7F5GI14/omwJrEo35SWiedd9wI)
  • Since the text of input must be manually changed from the code, here is how to change it, Go to `const o=rot("Hello World",4);` and change the text between `""` to something like `const o=rot("Codidact Code Golf",4);` or anything you like then run.
  • # [Javascript (V8)](https://v8.dev/), 202 bytes
  • ```js
  • function rot(o,r){return o.replace(/[a-zA-Z]/g,function(o){return String.fromCharCode((o<="Z"?90:122)>=(o=o.charCodeAt(0)+r)?o:o-26)})}(function update(){const o=rot("Hello World",4);console.log(o)})();
  • ```
  • [Try it online!](https://tio.run/##Pc7NCoJAFIbhWxFX55BaSUR/FtGmfYugaDGMoxnTfHIaWxReuxVU6/ddPBd1VzctVe3j@6TrisZpX8EFAk@IhJ9ifCMuQCKmtkob6h9V/FjHh1O/jH474T/uvFSuTArBdXNWskFuiLDIwkO4mg5mwzTlZUbIkOhvXnsacE94hRnidMwtt/R3NHWuvCF@aribD5B9YOHWWItgD7F5GI14/omwJrEo35SWiedd9wI)
  • Since the text of input must be manually changed from the code, here is how to change it, Go to `const o=rot("Hello World",4);` and change the text between `""` (string) to something like `const o=rot("Codidact Code Golf",4);` or anything you like then run. also you can change ROT$n$ by changing number 4 in `const o=rot("Hello World",4);` to anything you like `const o=rot("Hello World",13);`.
#3: Post edited by user avatar Kevin M. Mansour‭ · 2021-07-28T11:03:27Z (over 3 years ago)
Codidact
  • # [Javascript (V8)](https://v8.dev/), 202 bytes
  • ```js
  • function rot(o,r){return o.replace(/[a-zA-Z]/g,function(o){return String.fromCharCode((o<="Z"?90:122)>=(o=o.charCodeAt(0)+r)?o:o-26)})}(function update(){const o=rot("Hello World",4);console.log(o)})();
  • ```
  • [Try it online!](https://tio.run/##Pc7NCoJAFIbhWxFX55BaSUR/FtGmfYugaDGMoxnTfHIaWxReuxVU6/ddPBd1VzctVe3j@6TrisZpX8EFAk@IhJ9ifCMuQCKmtkob6h9V/FjHh1O/jH474T/uvFSuTArBdXNWskFuiLDIwkO4mg5mwzTlZUbIkOhvXnsacE94hRnidMwtt/R3NHWuvCF@aribD5B9YOHWWItgD7F5GI14/omwJrEo35SWiedd9wI)
  • Since the text of input must be manually changed from the code, here is how to change it, Go to `const o=rot("Hello World",4);` and change the text between `""` to something like `const o=rot("Codidacr Code Golf",4);` or anything you like then run.
  • # [Javascript (V8)](https://v8.dev/), 202 bytes
  • ```js
  • function rot(o,r){return o.replace(/[a-zA-Z]/g,function(o){return String.fromCharCode((o<="Z"?90:122)>=(o=o.charCodeAt(0)+r)?o:o-26)})}(function update(){const o=rot("Hello World",4);console.log(o)})();
  • ```
  • [Try it online!](https://tio.run/##Pc7NCoJAFIbhWxFX55BaSUR/FtGmfYugaDGMoxnTfHIaWxReuxVU6/ddPBd1VzctVe3j@6TrisZpX8EFAk@IhJ9ifCMuQCKmtkob6h9V/FjHh1O/jH474T/uvFSuTArBdXNWskFuiLDIwkO4mg5mwzTlZUbIkOhvXnsacE94hRnidMwtt/R3NHWuvCF@aribD5B9YOHWWItgD7F5GI14/omwJrEo35SWiedd9wI)
  • Since the text of input must be manually changed from the code, here is how to change it, Go to `const o=rot("Hello World",4);` and change the text between `""` to something like `const o=rot("Codidact Code Golf",4);` or anything you like then run.
#2: Post edited by user avatar Kevin M. Mansour‭ · 2021-07-28T11:03:01Z (over 3 years ago)
Cleaning Up.
  • # [Javascript V8](https://v8.dev/), 202 bytes
  • ```js
  • function rot(o,r){return o.replace(/[a-zA-Z]/g,function(o){return String.fromCharCode((o<="Z"?90:122)>=(o=o.charCodeAt(0)+r)?o:o-26)})}(function update(){const o=rot("Hello World",4);console.log(o)})();
  • ```
  • [Try it online!](https://tio.run/##Pc7NCoJAFIbhWxFX55BaSUR/FtGmfYugaDGMoxnTfHIaWxReuxVU6/ddPBd1VzctVe3j@6TrisZpX8EFAk@IhJ9ifCMuQCKmtkob6h9V/FjHh1O/jH474T/uvFSuTArBdXNWskFuiLDIwkO4mg5mwzTlZUbIkOhvXnsacE94hRnidMwtt/R3NHWuvCF@aribD5B9YOHWWItgD7F5GI14/omwJrEo35SWiedd9wI)
  • # [Javascript (V8)](https://v8.dev/), 202 bytes
  • ```js
  • function rot(o,r){return o.replace(/[a-zA-Z]/g,function(o){return String.fromCharCode((o<="Z"?90:122)>=(o=o.charCodeAt(0)+r)?o:o-26)})}(function update(){const o=rot("Hello World",4);console.log(o)})();
  • ```
  • [Try it online!](https://tio.run/##Pc7NCoJAFIbhWxFX55BaSUR/FtGmfYugaDGMoxnTfHIaWxReuxVU6/ddPBd1VzctVe3j@6TrisZpX8EFAk@IhJ9ifCMuQCKmtkob6h9V/FjHh1O/jH474T/uvFSuTArBdXNWskFuiLDIwkO4mg5mwzTlZUbIkOhvXnsacE94hRnidMwtt/R3NHWuvCF@aribD5B9YOHWWItgD7F5GI14/omwJrEo35SWiedd9wI)
  • Since the text of input must be manually changed from the code, here is how to change it, Go to `const o=rot("Hello World",4);` and change the text between `""` to something like `const o=rot("Codidacr Code Golf",4);` or anything you like then run.
#1: Initial revision by user avatar Kevin M. Mansour‭ · 2021-07-28T10:42:18Z (over 3 years ago)
# [Javascript V8](https://v8.dev/), 202 bytes

```js
function rot(o,r){return o.replace(/[a-zA-Z]/g,function(o){return String.fromCharCode((o<="Z"?90:122)>=(o=o.charCodeAt(0)+r)?o:o-26)})}(function update(){const o=rot("Hello World",4);console.log(o)})();
```

[Try it online!](https://tio.run/##Pc7NCoJAFIbhWxFX55BaSUR/FtGmfYugaDGMoxnTfHIaWxReuxVU6/ddPBd1VzctVe3j@6TrisZpX8EFAk@IhJ9ifCMuQCKmtkob6h9V/FjHh1O/jH474T/uvFSuTArBdXNWskFuiLDIwkO4mg5mwzTlZUbIkOhvXnsacE94hRnidMwtt/R3NHWuvCF@aribD5B9YOHWWItgD7F5GI14/omwJrEo35SWiedd9wI)