Created
August 6, 2015 11:58
-
-
Save larryprice/2c91df40da49d55eec58 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
if (process.argv.length !== 3) { | |
console.log("Usage:", process.argv[1], "num") | |
return; | |
} | |
var garland = function (word) { | |
var degree = 0; | |
for (var i = 1; i < word.length; ++i) { | |
var front = word.slice(0, i); | |
for (var j = 1; j <= i; ++j) { | |
var back = word.slice(-j); | |
if (front === back && front.length > degree) { | |
degree = front.length; | |
} | |
} | |
} | |
return degree; | |
} | |
console.log(garland(process.argv[2])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment