import { NullablePosition } from 'src/types/position';

export const comparePositions = <TData extends NullablePosition>(
  a: TData,
  b: TData,
): number => {
  if (a.position == null || b.position == null) return 0;
  return a.position - b.position;
};

export const sortByPosition = <TData extends NullablePosition>(
  list: TData[],
): TData[] => list?.sort(comparePositions);
