Created
August 27, 2021 12:29
-
-
Save itashdv/1269d01d942df4069f4cd5094b9f1cee to your computer and use it in GitHub Desktop.
Case insensitive sorting with ramda sortWith
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { sortWith, path, split, ascend, descend } from "ramda"; | |
const theList = [ | |
{ | |
name: "C", | |
purchase: { | |
period: { | |
start: "2020-01-26T21: 00: 00Z", | |
end: "3070-10-27T21: 00: 00Z", | |
}, | |
}, | |
}, | |
{ | |
name: "A", | |
purchase: { | |
period: { | |
start: "2020-01-08T21: 00: 00Z", | |
end: "3070-10-27T21: 00: 00Z", | |
}, | |
}, | |
}, | |
{ | |
name: "b", | |
purchase: { | |
period: { | |
start: "2019-09-30T19: 00: 00Z", | |
end: "3070-10-27T21: 00: 00Z", | |
}, | |
}, | |
}, | |
]; | |
const makeSorter = compose( | |
sortWith, | |
map(({ order, name }) => | |
(order == "desc" ? descend : ascend)( | |
compose(toLower, path(split(".", name))) | |
) | |
) | |
); | |
const sorts = [ | |
{ order: "asc", name: "name" }, | |
{ order: "desc", name: "purchase.period.start" }, | |
]; | |
const result = makeSorter(sorts)(theList); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi Aitash im ibrahim from Antalya I need to talk to you