25 lines
691 B
TypeScript
25 lines
691 B
TypeScript
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 };
|