Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getItemsFromJSONData(data, wordtype)
- {
- var items = new LinkedList();
- console.log(Object.keys(data[0]));
- console.log(data[0].tags);
- if(wordtype == "*")
- {
- for(var i = 0, length = data.length; i < length; i++)
- if(frequencyMeetsRequirement(data.tags))
- items.add(data[i].word);
- }
- else
- {
- for(var i = 0, length = data.length; i < length; i++)
- if(frequencyMeetsRequirement(data.tags))
- if(arrayContains(data[i].tags, wordtype))
- items.add(data[i].word);
- }
- return items;
- }
- const frequencyRequirement = 0.35;
- function frequencyMeetsRequirement(tags)
- {
- console.log(tags)
- for(var i = 0, tag = tags[0]; i < tags.length; tag = tags[++i])
- {
- if(tag.startsWith("f:"))
- {
- var numString = tag.substring(2, tag.length);
- var num = parseFloat(numString);
- return num >= frequencyRequirement;
- }
- }
- return false;
- }
- Console log:
- Array [ "word", "score", "numSyllables", "tags" ] script.html:52:5
- Array [ "n", "adj", "v", "f:151.019815" ] script.html:53:5
- undefined script.html:76:5
- Array [ "word", "score", "numSyllables", "tags" ] script.html:52:5
- Array [ "v", "n", "f:5.154289" ] script.html:53:5
- undefined script.html:76:5
- Array [ "word", "score", "numSyllables", "tags" ] script.html:52:5
- Array [ "adj", "f:1.479037" ] script.html:53:5
- undefined script.html:76:5
- TypeError: tags is undefined[Learn More] script.html:78:20 (That's line 31 in this paste)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement