This is kinda a logic question. I tried hard, but just couldn't solve it!
For eg.
I have an array: ["tech", "review", "howto"]
.
I have another huge array with id(s) and texts.
[
{ id: "tech", text: "Technology" },
{ id: "fin", text: "Finance" },
{ id: "digimark", text: "Digital Marketing" },
{ id: "coding", text: "Programming" },
{ id: "tutorial", text: "Tutorial" },
{ id: "howto", text: "How To" },
{ id: "writing", text: "Writing" },
{ id: "inspire", text: "Inspirational" },
{ id: "science", text: "Science" },
{ id: "politics", text: "Politics" },
{ id: "lifestyle", text: "Lifestyle" },
{ id: "food", text: "Food" },
{ id: "business", text: "Business" },
{ id: "entrepreneur", text: "Entrepreneurs" },
{ id: "history", text: "History" },
{ id: "health", text: "Health" },
{ id: "pet", text: "Pets" },
{ id: "parenthood", text: "Parenthood" },
{ id: "travel", text: "Travel" },
{ id: "india", text: "India" },
{ id: "china", text: "China" },
{ id: "uk", text: "United Kingdom" },
{ id: "us", text: "United States" },
{ id: "world", text: "World" },
{ id: "news", text: "News" },
{ id: "review", text: "Product Review" }
]
Using those assets, I want this response in javascript:
[
{ id: "tech", text: "Technology" },
{ id: "review", text: "Product Review" },
{ id: "howto", text: "How To" }
]
As per now, I am doing this
categorySorter(categories) {
const categoryState = categorySuggessions.filter(category => category.id === categories.map(category => (category)))
return categoryState
}
That returns me a blank (i.e. []
) array.
What would you suggest?
NEWBIE HERE.