I have millions of objects of messages
messages: [
{
id: Int,
text: String,
userId: Int,
receiverId: Int,
},
and thousands of users
users: [
{
id: Int,
name: String,
},
I need to process two objects and return an object in format
[{ message, userFromName, userToName }]
I read about array methods like find, filter, some and all of these are slower than native for and foreach.
I also wrote a function which two foreach loops
msgData.forEach(function(msg,i) {
...iterating every msg
userData.forEach(function(user) {
...iterating every user id over message sender and receiver id
});
});
The complexity of the code O(n)square
How to get the required format in less amount of time?