Circular shift Roman letters in CoffeeScript

in code

This Codewars problem annoyed the crap out of me.

shift = (letter, amount) ->
  mod = if /[A-Z]/.test letter then 65 else 97
  String.fromCharCode mod + (letter.charCodeAt(0) + amount) % mod % 26

The formula to constrain a number to a range is:

(range_start + offset_here) % range_start % range_size

Six Months in the Mountain Kingdom

in me

Your email address will not be published. Required fields are marked *