diff --git a/app/utils.jsx b/app/utils.jsx index 9265fba..6bc7ecc 100644 --- a/app/utils.jsx +++ b/app/utils.jsx @@ -222,3 +222,50 @@ export function compareNotebooks(a, b) { return -1 return 0 } + +export function dateDesc(a, b){ + return b.created_at - a.created_at +} + +export function dateAsc(a, b){ + return a.created_at - b.created_at +} + +export function titleAsc(a, b){ + let atitle = a.title.toLowerCase() + let btitle = b.title.toLowerCase() + + if(atitle > btitle) + return 1 + if(atitle < btitle) + return -1 + return 0 +} + +export function titleDesc(a, b){ + let atitle = a.title.toLowerCase() + let btitle = b.title.toLowerCase() + + if(atitle < btitle) + return 1 + if(atitle > btitle) + return -1 + return 0 +} + +const defaultOrder = [ + dateDesc, + titleAsc +] + +export function compareNotes(ordering = defaultOrder) { + return (a, b) => { + for(var i=0; i