Bang for Your Buck: Solution Review
Solution review.
We'll cover the following...
We'll cover the following...
Review
Let’s review the steps
- Get everything
maxPriceor less - Sort by rating
- Get the top 3
Here’s a vanilla solution
Ramda has slice and sort functions. Using them lets us pipe the entire function to make it point-free.
We can point-free up filter's predicate function using propSatisfies. It tests an object’s property against a function to return true or false.
I personally wouldn’t do that, but it’s fun to experiment.
Comparators
I would, however, play around with comparators. These are functions that compare data for sorting.
Ramda’s descend function is a descending comparator, meaning a function that sorts entries from biggest to smallest. The flip side would be R.ascend, an ascending comparator.
We can break the sorting logic into a function
const byPrice = descend(prop('rating'));
Then use it like so
sort(byPrice);
It reads like a sentence!