ai-tube / src /components /interface /latent-engine /utils /data /getElementsSortedByStartAt.ts
jbilcke-hf's picture
jbilcke-hf HF staff
Modifying AiTube to support Stories Factory use cases
6215321
raw
history blame
No virus
467 Bytes
import { getSegmentStartAt } from "./getSegmentStartAt"
export function getElementsSortedByStartAt<T extends HTMLElement>(elements: T[], createCopy = true): T[] {
const array = createCopy ? [...elements]: elements
// this sort from the smallest (oldest) to biggest (youngest)
return array.sort((a, b) => {
const aSegmentStartAt = getSegmentStartAt(a)
const bSegmentStartAt = getSegmentStartAt(b)
return aSegmentStartAt - bSegmentStartAt
})
}