Skip to content

Instantly share code, notes, and snippets.

@vamdt vamdt/odd_collection.js
Last active Aug 29, 2015

Embed
What would you like to do?
数字求奇数数集合
//数字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
You can’t perform that action at this time.