https://github.com/bell-kevin/reverseorrotate
The input is a string str of digits. Cut the string into chunks (a chunk here is a substring of the initial string) of size sz (ignore the last chunk if its size is less than sz). If a chunk represents an integer such as the sum of the cubes of its digits is divisible by 2, reverse that chunk; otherwise rotate it to the left by one position. Put together these modified chunks and return the result as a string. If sz is <= 0 or if str is empty return "" sz is greater (>) than the length of str it is impossible to take a chunk of size sz hence return "". Examples: revrot("123456987654", 6) --> "234561876549" revrot("123456987653", 6) --> "234561356789" revrot("66443875", 4) --> "44668753" revrot("66443875", 8) --> "64438756" revrot("664438769", 8) --> "67834466" revrot("123456779", 8) --> "23456771" revrot("", 8) --> "" revrot("123456779", 0) --> "" revrot("563000655734469485", 4) --> "0365065073456944" Example of a string rotated to the left by one position: s = "123456" gives "234561".
https://github.com/bell-kevin/reverseorrotate
codewars-kata-solution
Last synced: 8 months ago
JSON representation
The input is a string str of digits. Cut the string into chunks (a chunk here is a substring of the initial string) of size sz (ignore the last chunk if its size is less than sz). If a chunk represents an integer such as the sum of the cubes of its digits is divisible by 2, reverse that chunk; otherwise rotate it to the left by one position. Put together these modified chunks and return the result as a string. If sz is <= 0 or if str is empty return "" sz is greater (>) than the length of str it is impossible to take a chunk of size sz hence return "". Examples: revrot("123456987654", 6) --> "234561876549" revrot("123456987653", 6) --> "234561356789" revrot("66443875", 4) --> "44668753" revrot("66443875", 8) --> "64438756" revrot("664438769", 8) --> "67834466" revrot("123456779", 8) --> "23456771" revrot("", 8) --> "" revrot("123456779", 0) --> "" revrot("563000655734469485", 4) --> "0365065073456944" Example of a string rotated to the left by one position: s = "123456" gives "234561".
- Host: GitHub
- URL: https://github.com/bell-kevin/reverseorrotate
- Owner: bell-kevin
- License: gpl-3.0
- Created: 2022-06-28T16:28:40.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-07-06T22:48:48.000Z (almost 4 years ago)
- Last Synced: 2025-01-23T16:48:46.312Z (over 1 year ago)
- Topics: codewars-kata-solution
- Language: JavaScript
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0