DEV Community

Discussion on: Using the JavaScript `reduce` method to optimize my React To Do app

Collapse
 
vberlier profile image
Valentin Berlier

It's better than what you had before but the whole thing could still be done with a single call to the sort method and a custom comparison function. Also you should avoid repeatedly calling Date.parse in the comparison function. On average the number of comparison is O(n log n) so your sortByDueDate function slows down the sorting algorithm tremendously by forcing it to do some date parsing every time it tries to compare two elements.

Collapse
 
twinfred profile image
Tim Winfred (They/He)

Thank you for the feedback. If you have time to share and wouldn't mind, I would love to see your solution!