'How to use Quick sort in MERN Stack project

I have got a task where I have to use Quicksort instead of using the (MongoDB) mongoose default sort method.

I could not find any solution on how to implement it.

Current code:

export const getProduct = expressAsyncHandler(async (req, res) => {
   const pageSize = req.headers.referer === DASHBOARD_SCREEN_ROUTE ? 12 : 6;
   const page = Number(req.query.pageNumber) || 1;
   const sortOrder =
      order === 'lowest'
         ? { price: 1 }
         : order === 'highest'
         ? { price: -1 }
         : order === 'toprated'
         ? { rating: -1 }
         : { _id: -1 };
   const products = await Product.find({})
      .sort(sortOrder)
      .skip(pageSize * (page - 1))
      .limit(pageSize);
   try {
      res.send({ products });
   } catch (error) {
      console.log(error);
      res.status(512).send(error.message);
   }
});

Instead of .sort method, I have to use quick sort there.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source