Created
July 10, 2019 01:27
-
-
Save k-vosswinkel/39d5e0ebcbe1e7f4c6c1cb8438cc1052 to your computer and use it in GitHub Desktop.
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
/* 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