mirror of
https://github.com/10h30/astroplate.git
synced 2026-07-11 18:56:06 +09:00
initialize project
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
// sort by date
|
||||
export const sortByDate = (array: any[]) => {
|
||||
const sortedArray = array.sort(
|
||||
(a:any, b:any) =>
|
||||
new Date(b.data.date && b.data.date) -
|
||||
new Date(a.data.date && a.data.date)
|
||||
);
|
||||
return sortedArray;
|
||||
};
|
||||
|
||||
// sort product by weight
|
||||
export const sortByWeight = (array: any[]) => {
|
||||
const withWeight = array.filter(
|
||||
(item: { data: { weight: any } }) => item.data.weight
|
||||
);
|
||||
const withoutWeight = array.filter(
|
||||
(item: { data: { weight: any } }) => !item.data.weight
|
||||
);
|
||||
const sortedWeightedArray = withWeight.sort(
|
||||
(a: { data: { weight: number } }, b: { data: { weight: number } }) =>
|
||||
a.data.weight - b.data.weight
|
||||
);
|
||||
const sortedArray = [...new Set([...sortedWeightedArray, ...withoutWeight])];
|
||||
return sortedArray;
|
||||
};
|
||||
Reference in New Issue
Block a user