Generate all the rotational permutations of a string

in code

This does not generate lexicographic permutations (use Lexicographer for that!); this plucks off one letter from the end and attaches it to the start:

rotations = (str) ->
  Array(str.length).fill(str).map (rotation, index) ->
    while index--
      rotation = rotation[-1..-1] + rotation[0..-2]


I liked my solution and wanted to share.

March 20

in me

Happy Dissonance

in me


in ireland

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