Fix Bug 2296: Newly Created Ns should come first in NG-UI
[osm/NG-UI.git] / src / services / SharedService.ts
index ba805e6..e8eac94 100644 (file)
@@ -468,6 +468,19 @@ export class SharedService {
         }));
     }
 
+    /** Sorting the list based on date @public */
+    public compareFunction = (dir: number, a: string, b: string): number => {
+        const first: number = new Date(a).getTime();
+        const second: number = new Date(b).getTime();
+        if (first < second) {
+            return -1 * dir;
+        }
+        if (first > second) {
+            return dir;
+        }
+        return 0;
+    };
+
     /** Method to validate file extension and size @private */
     private vaildataFileInfo(fileInfo: File, fileType: string): boolean {
         const extension: string = fileInfo.name.substring(fileInfo.name.lastIndexOf('.') + 1);