Created
July 2, 2014 19:54
-
-
Save scazon/88b39735bdee634ccbf8 to your computer and use it in GitHub Desktop.
Can't spell a thing without this other thing
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
function makeTweet(bot){ | |
var tweet = ""; | |
var subWord = ""; | |
while (subWord == ""){ | |
var word = getRandomWord(); //get random word from Wordnik API | |
var startIndex = 1; //starting with second letter in word, search for | |
var endIndex = 5; //all 4+ letter substrings for new words | |
var possibleWords = []; | |
while (startIndex <= word.length - 4 && endIndex <= word.length){ | |
var testString = word.slice(startIndex, endIndex); | |
if (words.indexOf(testString) != -1){ //search list of scrabble words for substring words | |
possibleWords.push(testString); | |
} | |
endIndex ++; | |
if (endIndex == word.length+1){ | |
startIndex ++; | |
endIndex = startIndex + 4; | |
} | |
} | |
if (possibleWords.length > 0){ | |
subWord = randomChoice(possibleWords); | |
} | |
} | |
tweet = "Can't spell "+word+" without "+subWord+"."; | |
tweet = encodeString(tweet); //URI-encodes tweet for HTTP post request | |
return tweet; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment