Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save k-vosswinkel/39d5e0ebcbe1e7f4c6c1cb8438cc1052 to your computer and use it in GitHub Desktop.
Save k-vosswinkel/39d5e0ebcbe1e7f4c6c1cb8438cc1052 to your computer and use it in GitHub Desktop.
/* eslint-disable no-unused-vars */
const rotater = str => {
let flip = false;
let rotatedStr;
return function (steps) {
if (steps === str.length) {
flip = !flip;
}
if (!flip) {
rotatedStr = `${str.slice(steps)}${str.slice(0, steps)}`;
} else {
rotatedStr = `${str.slice(str.length - steps)}${str.slice(0, str.length - steps)}`;
}
return rotatedStr;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment