import { TransformerFunction } from './TransformerFunction';

/**
 * Performs sort on a Numeric or String array
 * @param arr Array to be sorted
 * @param ascending if true array will be sorted in ascending order, if false array will be sorted in descending order
 */
export const sortArray: TransformerFunction<
  string[] | number[],
  string[] | number[]
> = (arr): string[] | number[] => {
  if (!arr || arr.length < 2) {
    return arr;
  }
  return arr.slice().sort((v1: number | string, v2: number | string) => {
    return v1 > v2 ? 1 : -1;
  });
};
