Skip to content

Tag: sorting

Sort the array of database object-id

I have a array of mongodb object-id and i want to sort them in such a way that similar IDs are next to each other example : Input : var array = [“507f191e810c19729de860ea”,”00000020f51bb4362eee2a4d”,” 507f191e810c19729de860ea”] Output : var array = [“507f191e810c19729de860ea&#822…

Merge sort time complexity check

Hello guys I was learning about the merge sort so I wrote this function that takes 2 arrays and merges them sorted. Can someone tell me the time complexity of this function? I thought it would be O(n^2) as I am using shift inside a while loop. Is that correct or am I missing something here? Answer The worst c…

How to sort prompt answer by price

I’m having a small project where I have to do a shopping list (for fruit salad) which allows user to add products and set prices for them. I’ve managed to do this so far that the “final” prompt shows all added products and prices for the user. Problem is that it should show all this fr…

JavaScript: Comparing Two objects in one array

I’m new to this world of vanilla javascript. I’ve been trying complete some challenges but it seems like I’m unable to find the solution to a challenge. The task is:”Sort array by object property” Write a function that takes an array of objects as an argument Sort the array by pr…

Array.sort() on multiple properties

I have an array, productData with multiple properties. This is how I currently sort the array by monthlyCost, ascending. How can I modify this to sort all items by a boolean property isPromoted, followed by monthlyCost? My array should start with all items where isPromoted == true sorted by monthlyCost, then …