javascript - 170k item array not being processed correctly -
i have fiddle (note: accesses 2k file via jsonp). has small word list @ load consisting of 2 , 3 letter words, loaded array. it's filtered using array.prototype.filter
. works.
then page starts downloading enable1 word list (used games featuring word list). @ point, filter functions ends empty array, instead of expected 105 words.
i can confirm that, both before , after,
- my word list has same starting word (
aa
) should displayed, - the lists have 1091 , 172820 words respectively
- all words lowercase, , have no surrounding spaces
- on load, filtering criteria "has 2 letters"
- there no errors on console
- there 100mb (25%) increase in fiddle's page's ram usage, system has 35% ram remaining
here's code.
function vm() { var self = this; self.characters = ko.observable(2); self.words = ko.observablearray(document.getelementbyid("words") .innerhtml.split(/\s+/g).slice(1, -1) .map(function (word) { return word.tolowercase(); })); self.possible = ko.computed(function () { var letters = self.letters(), starters = self.startswith(), enders = self.endswith(), characters = self.characters(); return self.words().filter(function (word) { return word.length === parseint(characters); }) .filter(function (word) { if (enders === "") return true; (var = enders.length; >= 0; --i) { if (word.slice(-1) === enders[i]) return true; } return false; })/* other filtering code */; }); } ko.applybindings(app = new vm); $.getjson('http://anyorigin.com/get?url=https://scrabble-dictionary-search.googlecode.com/svn-history/r6/trunk/src/main/resources/enable1.txt&callback=?', function(data){ app.words(data.contents.split("\n")); console.log(app.words().length); });
what causing this? how can work same smaller list?
i think problem when "split" result of ajax call. if log array obtain when split response, see things that: "aa\r".
if use:
app.words(data.contents.split("\r\n"));
instead of:
app.words(data.contents.split("\n"));
that better.
Comments
Post a Comment