This is my code, which gets the most common words in English from Wikipedia, then collects all the words on the page and filters the most common words from the list of words:
// get table data from most common words
var arr = [];
$.ajax({
url: 'https://en.wikipedia.org/wiki/Most_common_words_in_English',
})
.done(function(html) {
var table = $(html).find(".wikitable");
for(var i = 1; i < 101; i++) {
arr[i - 1] = table[0].rows[i].children[0].innerText;
}
});
var text = document.getElementById('content').innerText;
var words = text.split(/[^a-zA-Z]/);
//filter empty strings
words = words.filter(Boolean);
//filter single characters
words = words.filter(function(word) {
return word.length > 1;
});
words = words.filter(function(word) {
return word !== 'was';
});
words = words.filter(function(word) {
return word !== 'where';
});
words = words.filter(function(word) {
return word !== 'is';
});
words = words.filter(function(word) {
return word !== 'are';
});
// filter stopWords from 100 most common words wikipedia page
words = words.filter(function(word) {
var isNotStopWord = true;
var i = 0;
for(var stopWord in arr) {
if(word === arr[i++]) {
isNotStopWord = false;
break;
}
}
return isNotStopWord;
});
But this last block of code doesn't seem to run:
// filter stopWords from 100 most common words wikipedia page
words = words.filter(function(word) {
var isNotStopWord = true;
var i = 0;
for(var stopWord in arr) {
if(word === arr[i++]) {
isNotStopWord = false;
break;
}
}
return isNotStopWord;
});
Unless I paste that part onto the console and run it again?
'); });` – mplungjan Sep 10 '17 at 07:23