test

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
1

export const sortCurrenciesByPriority = <T extends CurrencyDataItem>(
  currencies: Array<T>
): Array<T> =>
  currencies
    .filter((currency) =>
      PRIORITY_CURRENCY_CODES.includes(getCurrencyCode(currency))
    )
    .sort(
      (a, b) =>
        PRIORITY_CURRENCY_CODES.indexOf(getCurrencyCode(a)) -
        PRIORITY_CURRENCY_CODES.indexOf(getCurrencyCode(b))
    );
ready
2
export const sortCurrenciesByPriority = <T extends CurrencyDataItem>(
  currencies: Array<T>,
  priorityCodes: string[] = PRIORITY_CURRENCY_CODES
): Array<T> => {
  const priorityMap = new Map(
    priorityCodes.map((code, index) => [code, index])
  );

  return currencies
    .filter((currency) => priorityMap.has(getCurrencyCode(currency)))
    .sort(
      (a, b) =>
        (priorityMap.get(getCurrencyCode(a)) ?? Infinity) -
        (priorityMap.get(getCurrencyCode(b)) ?? Infinity)
    );
};
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.