sortDates
Signature
Section titled “Signature”sortDates(dates: string[], order?: "asc" | "desc"): string[]import { sortDates } from "@northguild/gmt/plain/calculate";Sort an array of PlainDate values in ascending or descending order.
- Returns empty array if no valid dates.
- Validation is performed on each item in the array.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
dates |
string[] |
Array of ISO PlainDate strings (e.g. “2024-03-10”) |
order |
"asc" | "desc" |
“asc” for ascending (earliest first) | “desc” for descending (latest first) |
Returns
Section titled “Returns”Sorted array of date strings
Examples
Section titled “Examples”sortDates(["2024-03-10", "2024-01-01", "2024-02-15"]) // ["2024-01-01", "2024-02-15", "2024-03-10"]sortDates([]) // []