Skip to content

Instantly share code, notes, and snippets.

@godwhoa
Created November 22, 2015 01:08
Show Gist options
  • Save godwhoa/040cc3590e0f4ff290ca to your computer and use it in GitHub Desktop.
Save godwhoa/040cc3590e0f4ff290ca to your computer and use it in GitHub Desktop.
String.prototype.contains = function(it) {
return this.indexOf(it) != -1;
};
function suggest(word) {
var sug = new Array();
var lookup = dict[alpha[word[0]]]
for (var i = 0; i < lookup.length; i++) {
var j = lookup[i]
if (j.contains(word)) {
sug.push(j);
}
}
return sug
}
var suggestions;
$('#input').keyup(function(e) {
var val = $(this).val()
if (val.length > 1) {
suggestions = suggest(val)
$("#suggestions").val("")
for (var g = 0; g < suggestions.length; g++) {
$("#suggestions").val($("#suggestions").val() + ", " + suggestions[g])
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment