How to use array-sort - 10 common examples

To help you get started, we’ve selected a few array-sort examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rodi01 / Artboard-Plus-XD / src / commands / sortArtboards.js View on Github external
export function sortZA(selection, documentRoot) {
  // @ts-ignore
  const sortedArboards = arraySort(artboards(documentRoot.children), "name")

  sort(selection, sortedArboards)
}
github rodi01 / Artboard-Plus-XD / src / commands / sortArtboards.js View on Github external
export function sortAZ(selection, documentRoot) {
  // @ts-ignore
  const sortedArboards = arraySort(artboards(documentRoot.children), "name", {
    reverse: true
  })
  sort(selection, sortedArboards)
}
github doczjs / docz / core / docz / src / hooks / useMenus.ts View on Github external
const sortMenus = (first: Menus, second: Menus | undefined = []): Menus => {
  const sorted: Menus = sort(first, compareWithMenu(second), sortByName)

  return sorted.map(item => {
    if (!item.menu) return item
    const found = second.find(menu => menu.name === item.name)
    const foundMenu = found && found.menu

    return {
      ...item,
      menu: foundMenu
        ? sortMenus(item.menu, foundMenu)
        : sort(item.menu, sortByName),
    }
  })
}
github dcos / dcos-ui / plugins / nodes / src / js / components / NodesTable.tsx View on Github external
const sorter = (
  data: Node[],
  comparator: (a: Node, b: Node) => number,
  sortDirection: SortDirection
): Node[] => {
  return sort(data, [comparator, compareByHostname], {
    reverse: sortDirection !== "ASC"
  });
};
export default class NodesTable extends React.Component<
github dcos / dcos-ui / plugins / services / src / js / containers / services / ServicesTable.tsx View on Github external
) {
  const copiedData = data.slice();

  if (sortColumn === currentSortColumn) {
    return {
      data:
        sortDirection === currentSortDirection
          ? copiedData
          : copiedData.reverse(),
      sortColumn,
      sortDirection
    };
  }

  return {
    data: sort(copiedData, sortForColumn(sortColumn), {
      reverse: sortDirection !== "ASC"
    }),
    sortColumn,
    sortDirection
  };
}
github dcos / dcos-ui / plugins / services / src / js / components / GroupsQuotaOverviewTable.tsx View on Github external
public sortData = (
    groups: ServiceGroup[],
    sortColumn: string = this.state.sortColumn,
    sortDirection: SortDirection = this.state.sortDirection
  ): ServiceGroup[] =>
    sort(groups.slice(), sortForColumn(sortColumn), {
      reverse: sortDirection !== "ASC"
    });
github dcos / dcos-ui / plugins / nodes / src / js / columns / NodesTableIpColumn.tsx View on Github external
export function ipSorter(data: Node[], sortDirection: SortDirection): Node[] {
  const reverse = sortDirection !== "ASC";
  return sort(data, comparators, { reverse });
}
github doczjs / docz / core / docz / src / components / Docs.tsx View on Github external
{state.get(({ entries, config }) => {
        if (!entries || !config || !children) return null
        if (!isFn(children)) {
          throw new Error(
            'You need to pass a children as a function to your  component'
          )
        }

        const arr = Object.values(entries)

        /** TODO: remove all order and  logic from here in a breaking change */
        const menusArr = flatArrFromObject(arr, 'menu')
        const menus = sort(menusArr, (a: string, b: string) => compare(a, b))
        const descending = config.ordering === 'descending'
        const docs: Entry[] = sort(
          arr,
          (a: Entry, b: Entry) => compare(a.order, b.order, descending),
          (a: Entry, b: Entry) => compare(a.name, b.name)
        )

        return children({
          menus,
          docs,
          config,
        })
      })}
github doczjs / docz / core / docz / src / components / Docs.tsx View on Github external
{state.get(({ entries, config }) => {
        if (!entries || !config || !children) return null
        if (!isFn(children)) {
          throw new Error(
            'You need to pass a children as a function to your  component'
          )
        }

        const arr = Object.values(entries)

        /** TODO: remove all order and  logic from here in a breaking change */
        const menusArr = flatArrFromObject(arr, 'menu')
        const menus = sort(menusArr, (a: string, b: string) => compare(a, b))
        const descending = config.ordering === 'descending'
        const docs: Entry[] = sort(
          arr,
          (a: Entry, b: Entry) => compare(a.order, b.order, descending),
          (a: Entry, b: Entry) => compare(a.name, b.name)
        )

        return children({
          menus,
          docs,
          config,
        })
      })}
github dcos / dcos-ui / plugins / services / src / js / utils / ServiceTableUtil.js View on Github external
sortData(data, sortDirection, prop) {
    const compareFunction = getCompareFunctionByProp(prop);
    const comparators = [compareFunction];
    const reverse = sortDirection !== "ASC";

    return sort(data, comparators, { reverse });
  },

array-sort

Fast and powerful array sorting. Sort an array of objects by one or more properties. Any number of nested properties or custom comparison functions may be used.

MIT
Latest version published 7 years ago

Package Health Score

71 / 100
Full package analysis

Popular array-sort functions