Last active
August 29, 2015 14:03
-
-
Save vamdt/7e60f913c5eed0dac177 to your computer and use it in GitHub Desktop.
数字求奇数数集合
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//数字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