Created
May 25, 2017 17:58
-
-
Save LeeCheneler/887d2650207fc8bf919600bfeda00d39 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
// palindrome = (n, c) => { | |
// l = c.length | |
// s = '' | |
// a = n / 2 | |
// m = Math.min | |
// for (i = 0; i < a;) { | |
// s += c[m(l - 1, i++)] | |
// } | |
// for (i = n % 2 > 0 ? a - 1.5 : a - 1; i > -1;) { | |
// s += c[m(l - 1, i--)] | |
// } | |
// return s | |
// } | |
//palindrome=(n,c)=>{r=n%2>0;l=c.length;return`${c.slice(0,r?l-1:l)}${Array(Math.max(1,n-l*2)).fill(c[l-1]).join('')}${c.slice(0,r?l-1:l).split('').reverse().join('')}`} | |
//palindrome=(n,c)=>{c=[...c];s='';l=c.length-1;for(i=0;i<n/2;i++){s+=c[Math.min(l,i)]}for(i=n%2>0?n/2-1.5:(n/2)-1;i>-1;i--){s+=c[Math.min(l,i)]}return s} | |
//palindrome=(n,c)=>{c=[...c];s='';l=c.length-1;m=Math.min;for(i=0;i<n/2;i++){s+=c[m(l,i)]}for(i=n%2>0?n/2-1.5:(n/2)-1;i>-1;i--){s+=c[m(l,i)]}return s} | |
//palindrome=(n,c)=>{s='';l=c.length-1;m=Math.min;for(i=0;i<n/2;i++){s+=c[m(l,i)]}for(i=n%2>0?n/2-1.5:(n/2)-1;i>-1;i--){s+=c[m(l,i)]}return s} | |
//palindrome=(n,c)=>{a=n/2;s='';l=c.length-1;m=Math.min;for(i=0;i<a;i++){s+=c[m(l,i)]}for(i=n%2>0?a-1.5:a-1;i>-1;i--){s+=c[m(l,i)]}return s} | |
//palindrome=(n,c)=>{a=n/2;s='';l=c.length-1;m=Math.min;for(i=0;i<a;){s+=c[m(l,i++)]}for(i=n%2>0?a-1.5:a-1;i>-1;){s+=c[m(l,i--)]}return s} | |
//palindrome=(n,c)=>{l=c.length;s=c;for(i=n-l-1;i>-1;i--){s+=c[Math.min(l-1,i)]}return s} | |
//palindrome=(n,c)=>{l=c.length;for(i=n-l-1;i>-1;i--){c+=c[Math.min(l-1,i)]}return c} | |
//palindrome=(n,c)=>{l=c.length;for(i=n-l;i>0;){c+=c[Math.min(l-1,--i)]}return c} | |
//palindrome=(n,c)=>{for(l=c.length,i=n-l;i>0;)c+=c[Math.min(l-1,--i)];return c} | |
//palindrome=(n,c)=>{for(l=c.length,i=n-l;i;)c+=c[Math.min(l-1,--i)];return c} | |
//palindrome=(n,c)=>{for(l=c.length,i=n-l;i;)c+=c[--i<l-1?i:l-1];return c} | |
palindrome=(n,c)=>{for(l=c.length,i=n-l;i;)c+=c[--i<l-1?i:l-1];return c} | |
console.log(palindrome(10, 'ab')) | |
console.log(palindrome(10, 'ab').length) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment