Created
November 22, 2015 01:08
-
-
Save godwhoa/040cc3590e0f4ff290ca to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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