In my current project, I am working on verifying a submitted string against a set of letters. If the word_string
is "GAR", the expected output should be "GAR" because all these letters are found in the letter set.
However, I am facing an issue where some words are checked correctly while others are missing certain letters. For example, when the word_string
is "RAG", the output is just "R". Similarly, "FIG" returns "FG".
letterset = {0: "R", 1: "A", 2: "G", 3: "A", 4: "O", 5: "E", 6: "F", 7: "I"}
var ls = [];
for (prop in letterset) {
ls.push(letterset[prop]);
};
console.log(ls)
var word_string = '';
var word = document
.getElementById('word_container')
.childNodes;
for (var i in word) {
var w = word[i].innerHTML;
for (var prop=0; prop<ls.length; prop++) {
if (ls[prop] == w) {
console.log(w);
word_string += w;
ls.splice(prop);
}
}
}