This is a challenging logic problem that I've been struggling with.
For example, I have an array: ["tech", "review", "howto"]
. Along with a larger array containing ids and corresponding texts. 👇
[
{ id: "tech", text: "Technology" },
{ id: "fin", text: "Finance" },
...
{ id: "review", text: "Product Review" }
]
Using these arrays, I'm aiming to get the following output in JavaScript:
[
{ id: "tech", text: "Technology" },
{ id: "review", text: "Product Review" },
{ id: "howto", text: "How To" }
]
Currently, this is my approach 👇
categorySorter(categories) {
const categoryState = categorySuggessions.filter(category => category.id === categories.map(category => (category)))
return categoryState
}
However, this code snippet returns an empty array ([]
).
Any suggestions on how to improve this?
I am new to programming and would appreciate any guidance!