(memories: Memory[])
| 154 | } |
| 155 | |
| 156 | export function sortMemoriesByRecency(memories: Memory[]): Memory[] { |
| 157 | const withIndex = memories.map((m, i) => ({ m, i })); |
| 158 | withIndex.sort((a, b) => { |
| 159 | const ad = Date.parse(a.m.date); |
| 160 | const bd = Date.parse(b.m.date); |
| 161 | const aTime = Number.isFinite(ad) ? ad : 0; |
| 162 | const bTime = Number.isFinite(bd) ? bd : 0; |
| 163 | if (aTime !== bTime) return bTime - aTime; |
| 164 | return a.i - b.i; |
| 165 | }); |
| 166 | return withIndex.map((x) => x.m); |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * Half-life in days per memory type. |
no outgoing calls
no test coverage detected