Created
October 9, 2010 04:54
-
-
Save yuanchuan/617899 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(function(str){ | |
var maxPalin=''; | |
for(var i=0,len=str.length;i<len;++i){ | |
var letter=str[i],substr; | |
for(var j=i;j<len;++j){ | |
if(letter == str[j]){ | |
maxPalin=(function(substr){ | |
return (function(substr){ | |
for(var i=0,len=substr.length;i<=len/2-1;++i){ | |
if(substr[i] != substr[len-i-1]){ | |
return false; | |
} | |
} | |
return true; | |
}(substr)) ? (maxPalin.length<substr.length ? substr : maxPalin) : maxPalin; | |
}(substr=str.slice(i,j+1))); | |
} | |
} | |
} | |
return maxPalin; | |
}("fourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanewnationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreatedequalNowweareengagedinagreahtcivilwartestingwhetherthatnaptionoranynartionsoconceivedandsodedicatedcanlongendureWeareqmetonagreatbattlefiemldoftzhatwarWehavecometodedicpateaportionofthatfieldasafinalrestingplaceforthosewhoheregavetheirlivesthatthatnationmightliveItisaltogetherfangandproperthatweshoulddothisButinalargersensewecannotdedicatewecannotconsecratewecannothallowthisgroundThebravelmenlivinganddeadwhostruggledherehaveconsecrateditfaraboveourpoorponwertoaddordetractTgheworldadswfilllittlenotlenorlongrememberwhatwesayherebutitcanneverforgetwhattheydidhereItisforusthelivingrathertobededicatedheretotheulnfinishedworkwhichtheywhofoughtherehavethusfarsonoblyadvancedItisratherforustobeherededicatedtothegreattdafskremainingbeforeusthatfromthesehonoreddeadwetakeincreaseddevotiontothatcauseforwhichtheygavethelastpfullmeasureofdevotionthatweherehighlyresolvethatthesedeadshallnothavediedinvainthatthisnationunsderGodshallhaveanewbirthoffreedomandthatgovernmentofthepeoplebythepeopleforthepeopleshallnotperishfromtheearth")); |
This file contains hidden or 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
(function(str){ | |
var maxPalin=''; | |
function isPalin(substr){ | |
for(var i=0,len=substr.length;i<=len/2-1;++i){ | |
if(substr[i] != substr[len-i-1]){ | |
return false; | |
} | |
} | |
return true; | |
} | |
function group(seq,step){ | |
var len,g=[],i; | |
if(seq && step>0 && step<=(len=seq.length)){ | |
for(i=0,len-=step;i<=len;++i){ | |
g.push(seq.slice(i,i+step)); | |
} | |
} | |
return g; | |
} | |
for(var i=str.length;i>0;i--){ | |
var g=group(str,i); | |
for(var j=0;j<g.length;++j){ | |
if(isPalin(maxPalin=g[j])){ | |
return maxPalin; | |
} | |
} | |
} | |
}("fourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanewnationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreatedequalNowweareengagedinagreahtcivilwartestingwhetherthatnaptionoranynartionsoconceivedandsodedicatedcanlongendureWeareqmetonagreatbattlefiemldoftzhatwarWehavecometodedicpateaportionofthatfieldasafinalrestingplaceforthosewhoheregavetheirlivesthatthatnationmightliveItisaltogetherfangandproperthatweshoulddothisButinalargersensewecannotdedicatewecannotconsecratewecannothallowthisgroundThebravelmenlivinganddeadwhostruggledherehaveconsecrateditfaraboveourpoorponwertoaddordetractTgheworldadswfilllittlenotlenorlongrememberwhatwesayherebutitcanneverforgetwhattheydidhereItisforusthelivingrathertobededicatedheretotheulnfinishedworkwhichtheywhofoughtherehavethusfarsonoblyadvancedItisratherforustobeherededicatedtothegreattdafskremainingbeforeusthatfromthesehonoreddeadwetakeincreaseddevotiontothatcauseforwhichtheygavethelastpfullmeasureofdevotionthatweherehighlyresolvethatthesedeadshallnothavediedinvainthatthisnationunsderGodshallhaveanewbirthoffreedomandthatgovernmentofthepeoplebythepeopleforthepeopleshallnotperishfromtheearth")); |
This file contains hidden or 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
(function(str){ | |
var maxPalin=''; | |
function isPalin(substr){ | |
for(var i=0,len=substr.length;i<=len/2-1;++i){ | |
if(substr[i] != substr[len-i-1]){ | |
return false; | |
} | |
} | |
return true; | |
} | |
for(var i=0,len=str.length;i<len;++i){ | |
var letter=str[i],substr; | |
for(var j=i;j<len;++j){ | |
if(letter==str[j] && isPalin(substr=str.slice(i,j+1))){ | |
maxPalin=substr.length > maxPalin.length ? substr : maxPalin; | |
} | |
} | |
} | |
return maxPalin; | |
}("fourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanewnationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreatedequalNowweareengagedinagreahtcivilwartestingwhetherthatnaptionoranynartionsoconceivedandsodedicatedcanlongendureWeareqmetonagreatbattlefiemldoftzhatwarWehavecometodedicpateaportionofthatfieldasafinalrestingplaceforthosewhoheregavetheirlivesthatthatnationmightliveItisaltogetherfangandproperthatweshoulddothisButinalargersensewecannotdedicatewecannotconsecratewecannothallowthisgroundThebravelmenlivinganddeadwhostruggledherehaveconsecrateditfaraboveourpoorponwertoaddordetractTgheworldadswfilllittlenotlenorlongrememberwhatwesayherebutitcanneverforgetwhattheydidhereItisforusthelivingrathertobededicatedheretotheulnfinishedworkwhichtheywhofoughtherehavethusfarsonoblyadvancedItisratherforustobeherededicatedtothegreattdafskremainingbeforeusthatfromthesehonoreddeadwetakeincreaseddevotiontothatcauseforwhichtheygavethelastpfullmeasureofdevotionthatweherehighlyresolvethatthesedeadshallnothavediedinvainthatthisnationunsderGodshallhaveanewbirthoffreedomandthatgovernmentofthepeoplebythepeopleforthepeopleshallnotperishfromtheearth")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment