# JavaScript, 77 bytes a=>[...a+a].map((_,b)=>a-=-z.substring((b-=n)>0?b:0,b+n),a*=n=(z=a).length)|a <!-- begin snippet: js hide: false console: true babel: false --> <!-- language: lang-js --> f=a=>[...a+a].map((_,b)=>a-=-z.substring((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')); <!-- end snippet -->