Skip to content

Instantly share code, notes, and snippets.

@mirismaili
Last active August 16, 2021 15:31
Show Gist options
  • Save mirismaili/1668be429925087810f455326cbc4d86 to your computer and use it in GitHub Desktop.
Save mirismaili/1668be429925087810f455326cbc4d86 to your computer and use it in GitHub Desktop.
const fs = require("fs");
const keywords = JSON.parse(fs.readFileSync("keywords.txt").toString());
const news = JSON.parse(fs.readFileSync("news.txt").toString());
console.time();
news.reduce((foundNews, aNews) => {
const stack = keywords.reduce((stack, keyword) => {
if (aNews["title"].includes(keyword["title"]) || aNews["lead"]?.includes(keyword["title"]))
stack.push(keyword["title"]);
return stack;
}, []);
if (stack.length) {
foundNews.push([aNews["id"], stack]);
}
return foundNews
}, [])
console.timeEnd();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment