map.apps Bundle APIs 4.20.0
    Preparing search index...

    Function createStringWithNumberPartsComparator

    • Factory to create a string comparator which compares strings respecting numeric parts of the given strings. The comparator splits the input into string and numeric parts to compare them separately.

      Parameters

      • locale: string = ...

        locale, e.g. en or de.

      • ignoreCase: boolean = true

        true, if strings should be compared ignoring case, otherwise false.

      Returns Comparator<any>

      comparator for comparing strings with numeric parts

      const comparator = createStringWithNumberPartsComparator();
      const values = ["a1", "a10", "a2", "b1", "a20", "a3"];
      values.sort(comparator);
      assert.deepStrictEqual(["a1", "a2", "a3", "a10", "a20", "b1"], values);