# JavaScript, <s>77</s> 74 bytes

*Saved 3 bytes thanks to [Value Ink](https://codegolf.stackexchange.com/users/52194/value-ink)*

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

    f=a=>[...a+a].map((_,b)=>a-=-z.substr((b-=n)>0?b:0,b+n),a*=n=(z=a).length)|a

    console.log(f('123'));
    console.log(f('101'));
    console.log(f('12'));
    console.log(f('1234567'));
    console.log(f('102033'));

<!-- end snippet -->