huridocs/uwazi

View on GitHub
app/shared/data_utils/objectSorting.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import { compareStringLists } from './stringUtils';

const sortByStrings = <T>(arr: T[], stringIndices: ((obj: T) => string)[]) => {
  const compare = (a: any, b: any) => {
    const aList = stringIndices.map(index => index(a));
    const bList = stringIndices.map(index => index(b));
    return compareStringLists(aList, bList);
  };

  return arr.sort(compare);
};

export { sortByStrings };