Skip to content

Instantly share code, notes, and snippets.

@st98
Created February 6, 2015 21:49
Show Gist options
  • Save st98/cde3017e0ed38510829e to your computer and use it in GitHub Desktop.
Save st98/cde3017e0ed38510829e to your computer and use it in GitHub Desktop.
f('hoge', 3) === 'ehog';
function f(s, n) {
n %= s.length;
return s.slice(n) + s.slice(0, n);
}
function g(s, n) {
n %= s.length;
return (s + s).slice(n, n + s.length);
}
function h(s, n) {
var r = '';
for (var i = 0; i < s.length; i++) {
r += s[(i + n) % s.length];
}
return r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment