A photo manager for VRChat.
1import { Photo } from "../Structs/Photo"; 2 3// https://www.geeksforgeeks.org/typescript/how-to-use-merge-sort-with-typescript/ 4export let MergeSort = ( array: Photo[] ): Photo[] => { 5 if (array.length <= 1) { 6 return array; 7 } 8 const middle = Math.floor(array.length / 2); 9 const leftHalf = array.slice(0, middle); 10 const rightHalf = array.slice(middle); 11 return Merge(MergeSort(leftHalf), MergeSort(rightHalf)); 12} 13 14let Merge = ( left: Photo[], right: Photo[] ): Photo[] => { 15 let result: Photo[] = []; 16 let leftIndex = 0; 17 let rightIndex = 0; 18 19 while (leftIndex < left.length && 20 rightIndex < right.length) { 21 if (left[leftIndex].date > right[rightIndex].date) { 22 result.push(left[leftIndex]); 23 leftIndex++; 24 } else { 25 result.push(right[rightIndex]); 26 rightIndex++; 27 } 28 } 29 30 return result.concat(left.slice(leftIndex)).concat(right.slice(rightIndex)); 31}