javascript - How to filter out various titles with same keywords -
i have strings similar contain same keywords.
if more 1 string has 3 or more of same keywords, want 1 string returned.
example:
ex machina example of female artificial intelligence. ex machina, why artificial intelligence represented female? artificial intelligence represented females in ex machina?
i filter strings 3 keywords keep 1 string.
not sure if can use regex alone or need javascript.
help?
how looping on sentences , removing punctuation, , keeping words in map. aggregate count , loop on hash find words have occurred more 3
function filter() { var sentences = [ "ex machina example of female artificial intelligence.", "ex machina, why artificial intelligence represented female?", "will artificial intelligence represented females in ex machina?" ]; var word_map = {}; (var = 0; < sentences.length; i++) { var cur_sentence = sentences[i]; cur_sentence = remove_punctuations(cur_sentence).tolowercase().split(' '); cur_sentence.foreach(function(w) { if (word_map.hasownproperty(w)) { word_map[w] += 1; } else { word_map[w] = 1; } }); } console.log(word_map); } function remove_punctuations(w) { return w.replace(/[\.?,]/g, ''); }