31 lines
560 B
TypeScript
31 lines
560 B
TypeScript
|
export type Spell = {
|
||
|
name: string;
|
||
|
cost: number;
|
||
|
color: string;
|
||
|
category: string;
|
||
|
description: string;
|
||
|
reserveMagic?: boolean;
|
||
|
cantripMagic?: boolean;
|
||
|
}
|
||
|
|
||
|
export const spellSort = (a: Spell, b: Spell) => {
|
||
|
let compareValue = 0;
|
||
|
|
||
|
if (!a) {
|
||
|
return -1;
|
||
|
} else if (!b) {
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
compareValue = a.color.localeCompare(b.color);
|
||
|
|
||
|
if (compareValue == 0) {
|
||
|
compareValue = a.category.localeCompare(b.category);
|
||
|
|
||
|
if (compareValue == 0) {
|
||
|
compareValue = a.name.localeCompare(b.name);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return compareValue;
|
||
|
}
|