I am not able to find a best way to do it so i am asking here.
I have an array of object
let x = [{name: "Apple", message: {data: {}},
{name: "dell", message: {data: {}},
{name: "samsung", message: {data: {}}
];
now i have list of name that i need to check and if it is found in the array find the first one
like
let y = {laptop: ["Apple", "HP" ], phone: ["samsung", "Motorolla" ]
What i need
result = {
laptop: {
name: "Apple",
message: {
data: {}
},
phone: {
name: "samsung",
message: {
data: {}
}
}
}
this variable can be any data structure, right now best i can do is O(n ^2)
and this check need to be done more than 40 times a second so i want to be done in efficient way. Is there any way i can do this in best possible way.
Comments
Post a Comment