Home > Enterprise >  How to sort data with multiple filter in node.js express
How to sort data with multiple filter in node.js express

Time:11-19

I'm building a back-end service for my mobile application with express. I'm holding users location as "country name, city name, latitude and longitude" to compare nearby users. I was wondering are there any way to compare location for get nearby users with this data and after that use another filter (like interaction or count of follower) for the users at same location? And are there any specific name for this kind of sorting algorithms?

Thanks a lot in advance for your guidance.

CodePudding user response:

You can use basic sort method in witch you use haversine algorithm to determine the distance based on coordinates, also compare other user features and return -1, 0, 1 accordingly. Use reduce or map, to group users with the same location.

npm package with haversine implementation

  • Related