search page
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { ILayoutCard } from "../types/layoutCard";
|
||||
import { ISort } from "../types/sortType";
|
||||
|
||||
const sortCardBy = (sortTypeList: ISort[], layoutsCards: ILayoutCard[]) => {
|
||||
const sortType = sortTypeList.find((sort) => sort.isSelected);
|
||||
const sortedList = [...layoutsCards].sort((cardA, cardB) => {
|
||||
switch (sortType?.title) {
|
||||
case "Ascending price":
|
||||
return cardA.cost - cardB.cost;
|
||||
case "Decreasing price":
|
||||
return cardB.cost - cardA.cost;
|
||||
case "Ascending Squares":
|
||||
return cardA.square - cardB.square;
|
||||
case "Ascending Floor":
|
||||
return 1;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
|
||||
return sortedList;
|
||||
};
|
||||
|
||||
export { sortCardBy };
|
||||
Reference in New Issue
Block a user