Skip to content

Instantly share code, notes, and snippets.

@larryprice
Created August 6, 2015 11:58
Show Gist options
  • Save larryprice/2c91df40da49d55eec58 to your computer and use it in GitHub Desktop.
Save larryprice/2c91df40da49d55eec58 to your computer and use it in GitHub Desktop.
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