Why isn't the code functioning correctly when trying to push words to the answer array? After modifying the loop to:
for (var k in testDict) {
console.log(testDict[k].split("").sort());
}
The expected output is correctly displayed, which is an array of split and sorted characters from the words. I am confused as to why it's not evaluating properly and being pushed to the answer array. Any help would be appreciated!
function unscrambleWords(word, dictionary) {
var testDict = dictionary;
var answer = [];
var scrambledWord = word.split("").sort();
for (var k in testDict) {
if (scrambledWord === testDict[k].split("").sort())
answer.push(testDict[k]);
}
console.log(answer);
}
unscrambleWords("kevin", ["trees", "but", "ankle", "nevik", "knive", "evin"]);