Reputation: 21
I tried the following code but it doesn't work:
const startDate = ["2020-07-17", "2090-09-27", "1920-12-11"]
const pathComponents = R.split('-');
const sortDate = R.sortBy(R.ascend(pathComponents(R.prop(startDate))));
const sortDate = R.sortBy(R.prop('startDate'));
const sortDate = R.sortBy(R.descend( R.prop('startDate')));
Upvotes: 0
Views: 397
Reputation: 50797
I'm missing something here. I don't know if this is all you want to do, or if there is something additional going on:
const startDate = ["2020-07-17", "2090-09-27", "1920-12-11"]
const sortDate = sort (descend (identity), startDate)
console .log (sortDate)
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.27.0/ramda.js"></script>
<script> const {sort, descend, identity} = R </script>
Dates in that format are already intrinsically sortable; that's part of the point of the format.
Upvotes: 0
Reputation: 1409
You can use sort:
R.sort((a,b)=>new Date(b) - new Date(a), ["10 june 1859", "12 august 1387", "30 december 1998"]);
If you want it in descent just change new Date(b) - new Date(a)
for new Date(a) - new Date(b)
Snippet of the result with javascript vanilla:
console.log(["10 june 1859", "12 august 1387", "30 december 1998"].sort((a,b)=>new Date(b) - new Date(a)))
Upvotes: 1