Created
September 17, 2012 13:35
-
-
Save viig99/3737302 to your computer and use it in GitHub Desktop.
gremlin_1
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
var text = "FourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanewnationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreatedequalNowweareengagedinagreahtcivilwartestingwhetherthatnaptionoranynartionsoconceivedandsodedicatedcanlongendureWeareqmetonagreatbattlefiemldoftzhatwarWehavecometodedicpateaportionofthatfieldasafinalrestingplaceforthosewhoheregavetheirlivesthatthatnationmightliveItisaltogetherfangandproperthatweshoulddothisButinalargersensewecannotdedicatewecannotconsecratewecannothallowthisgroundThebravelmenlivinganddeadwhostruggledherehaveconsecrateditfaraboveourpoorponwertoaddordetractTgheworldadswfilllittlenotlenorlongrememberwhatwesayherebutitcanneverforgetwhattheydidhereItisforusthelivingrathertobededicatedheretotheulnfinishedworkwhichtheywhofoughtherehavethusfarsonoblyadvancedItisratherforustobeherededicatedtothegreattdafskremainingbeforeusthatfromthesehonoreddeadwetakeincreaseddevotiontothatcauseforwhichtheygavethelastpfullmeasureofdevotionthatweherehighlyresolvethatthesedeadshallnothavediedinvainthatthisnationunsderGodshallhaveanewbirthoffreedomandthatgovernmentofthepeoplebythepeopleforthepeopleshallnotperishfromtheearth" | |
function palindrome(word) { | |
var longest = ''; | |
var final_word = ''; | |
var adjusted_word = word; | |
for (var i = 0; i < word.length; i++) { | |
adjusted_word = word.substr(0,i); | |
for (var j = 0; j < adjusted_word.length; j++) { | |
for (var k = j; k < adjusted_word.length; k++) { | |
final_word = final_word + adjusted_word[k]; | |
} | |
if (final_word == final_word.split('').reverse().join('') && final_word.length > longest.length) | |
longest = final_word; | |
final_word = ''; | |
} | |
} | |
console.log("Longest palindrome is: " + longest); | |
} | |
palindrome(text); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment