Skip to content

Instantly share code, notes, and snippets.

@vamdt
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vamdt/7e60f913c5eed0dac177 to your computer and use it in GitHub Desktop.
Save vamdt/7e60f913c5eed0dac177 to your computer and use it in GitHub Desktop.
数字求奇数数集合
//数字shift1,change next to last
//eg:1234567890
// =>345678902..1
// =>5678904....3
// =>789046.....5
// =>90468......7
// =>4680.......9
// =>806........4
// =>60.........8
// =>0..........6
// =>...........0
//answer:
function c(str) {
var j ="", o="", m="";
if(str.length===1)
return str;
if(str.length%2) {
m=str.slice(-1);
str=str.slice(0,-1);
}
for(var i=0;i<str.length;i++) {
i%2 ? (j+=str.charAt(i)) : (o+=str.charAt(i));}
return o + c( m ? m+j : j);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment