Skip to content

Instantly share code, notes, and snippets.

@scazon
Created July 2, 2014 19:54
Show Gist options
  • Save scazon/88b39735bdee634ccbf8 to your computer and use it in GitHub Desktop.
Save scazon/88b39735bdee634ccbf8 to your computer and use it in GitHub Desktop.
Can't spell a thing without this other thing
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