10 examples of 'typescript sort by date' in JavaScript

Every line of 'typescript sort by date' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
86function sortDate(a, b) {
87 return b.timestamp - a.timestamp;
88}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

167export function sortByDate (a, b) {
168 return a.date - b.date
169}
361articles.sort(function dateSorter(a, b) {
362 return (Date.parse(b.date)) - (Date.parse(a.date));
363});
34function sortByDate(a, b) {
35 if (a.publishedOn < b.publishedOn) {
36 return 1;
37 } else if (a.publishedOn > b.publishedOn) {
38 return -1;
39 }
40 return 0;
41}
46public sortByDateTimeHelper(a: Date, b: Date): number {
47 if (a < b) {
48 return -1;
49 }
50
51 if (a > b) {
52 return 1;
53 }
54
55 return 0;
56}
15export function date_sort_asc (date1: Date, date2: Date) {
16 // This is a comparison function that will result in dates being sorted in
17 // ASCENDING order. As you can see, JavaScript's native comparison operators
18 // can be used to compare dates. This was news to me.
19 if (date1 > date2) return 1;
20 if (date1 < date2) return -1;
21 return 0;
22}
53function sortDates(allDates){
54 if (selection == "new" || selection == "updated") {
55 allDates.sort(function(a,b){return new Date(b.date) - new Date(a.date)}); // sorts the dates into ascending order
56 }
57 if (selection == "old") {
58 allDates.sort(function(a,b){return new Date(a.date) - new Date(b.date)}); // sorts the dates into descending order
59 }
60 return allDates;
61}
26export function byDateAsc(a, b) {
27 var dateA = a.abe_meta.date != null ? new Date(a.abe_meta.date) : 0
28 var dateB = b.abe_meta.date != null ? new Date(b.abe_meta.date) : 0
29 if (dateA > dateB) {
30 return 1
31 } else if (dateA < dateB) {
32 return -1
33 }
34 return 0
35}
11export default function sortDates(
12 arrayOfDates: Array<moment$Moment>
13): Array<moment$Moment> {
14 return arrayOfDates.sort(compareMomentDates);
15}
22function sortByCreatedAtDesc (a, b) {
23 return b.createdAt - a.createdAt
24}

Related snippets