Skip to content

Instantly share code, notes, and snippets.

@viig99
Created September 17, 2012 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viig99/3737302 to your computer and use it in GitHub Desktop.
Save viig99/3737302 to your computer and use it in GitHub Desktop.
gremlin_1
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