Operations on Table

Hello;

I need to do some operations on the below table, it is almost like sql query.
Please note that I do not need to use python because I need to do the operations before saving the document, so I am asking if possible to do it in .js and not in .py.

Below is the table and below of it what I need to do:

  1. Is there a method to order the records based on the first field (fees)?
  2. Is there a method to get the distinct values of fees field? And the sum of each distinct value?

I know that using for loop, I can create a logic, but before go into this scenario, I am checking if this is already existed so it is better to use it.

Regards
Bilal