mirror of
https://github.com/meshtastic/meshtastic.git
synced 2025-01-03 09:57:49 -08:00
9dc879235f
* initial devices.json * initial hardware components * testing page at /docs/hardware/supported/template * WIP Changes * Home page work & updates * Fix build * Fix external link button * Setup linting * rename, cleanup & lint * seperate lint cmd for now Co-authored-by: Foster Irwin <foster@jfirwin.com> Co-authored-by: Sacha Weatherstone <sachaw100@hotmail..om>
24 lines
646 B
TypeScript
24 lines
646 B
TypeScript
export const sortBy = <T>(array: T[], getter: (item: T) => unknown): T[] => {
|
|
const sortedArray = [...array];
|
|
sortedArray.sort((a, b) =>
|
|
// @ts-ignore
|
|
getter(a) > getter(b) ? 1 : getter(b) > getter(a) ? -1 : 0,
|
|
);
|
|
return sortedArray;
|
|
};
|
|
|
|
export const difference = <T>(...arrays: T[][]): T[] => {
|
|
return arrays.reduce((a, b) => a.filter((c) => !b.includes(c)));
|
|
};
|
|
|
|
export const toggleListItem = <T>(list: T[], item: T): T[] => {
|
|
const itemIndex = list.indexOf(item);
|
|
if (itemIndex === -1) {
|
|
return list.concat(item);
|
|
} else {
|
|
const newList = [...list];
|
|
newList.splice(itemIndex, 1);
|
|
return newList;
|
|
}
|
|
};
|