You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simple alphabet based sequencer. The first item is always 'a', then
increments by counting the alphabet.
Therefore in this system, we can treat 'a' as minimum and 'z' as the maximum.
BASE='a'.charCodeAt0MIN=0MAX=25
For example, here's a consecutive sequence of alphabet literals:
a, b, c, ..., y, z, aa, ab, ca, ..., zy, zz, aaa, aab, ... zzz, aaaa, ...
next= (input) ->
Convert each character in the input to an integer re-based on the integer
value of 'a'
input=input.split''integers=input.map (x) -> (x.charCodeAt0) - BASE
result=integers.map (x) -> x
Perform a simple add 1 arithmetic on the last token. If add 1 results in a
carry operation, they must cascade through until carry is set to false.
size=integers.length-1carry= integers[integers.length-1] is MAX
for integer, index inintegers.reverse()
if carry or index is0integer= integer +1carry=no
Wrap around addition: if a number exceeds the maximum value, it wraps around
and resets at the minimum value.
if integer > MAX
carry=yesinteger= MIN
result[size - index] = integer
If wrap around occurs at the first token, then length of the input must be
increased:
'bzz' -> 'caa' // no wrap around
'zzz' -> 'aaaa' // wrap around
if carry isyesresult.push MIN
result=result.map (x) ->String.fromCharCode (x + BASE)
result.join''module.exports= next
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters