Skip to content

Instantly share code, notes, and snippets.

@Ninjex
Created September 29, 2016 16:55
Show Gist options
  • Save Ninjex/ab1484f2cc21b2e18c9b0e77e2bb0d82 to your computer and use it in GitHub Desktop.
Save Ninjex/ab1484f2cc21b2e18c9b0e77e2bb0d82 to your computer and use it in GitHub Desktop.
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
function unscramble() {
var scrambled_words = document.getElementById('scrambled').value.split("\n");
var wordList = document.getElementById('wordlist').value.split("\n");
for (var i = 0; i < scrambled_words.length; i++) {
var scram_word = scrambled_words[i];
for (var x = 0; x < wordList.length; x++) {
var word_in_list = wordList[x];
console.log("Compare: " + scram_word + " : " + word_in_list);
a = sort_word(scram_word);
b = sort_word(word_in_list);
document.getElementById('compare_area').innerHTML += a + ' : ' + b;
sleep(5000)
if(a == b) {
console.log("TRUE!");
document.getElementById('solution_area').innerHTML += word_in_list + '</br>';
} else {
console.log("FALSE!");
}
document.getElementById('compare_area').innerHTML = '';
}
}
}
function sort_word(word) {
return word.split('').sort().join('');
}
function compare_letter(a, b) {
if(a == b) {
console.log('Letter match true');
} else {
console.log('Letter match: false');
}
}
console.log(sort_word('cat'));
compare_letter('a', 'a');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment