Function canReorder

  • Returns whether the given alternatives can all be reordered.

    In other words, given a set of alternatives, this will return whether all permutations of those alternatives behave exactly the same as the current permutation of those alternatives.

    The function makes one more guarantee when some alternatives of the same parent are not given. Let T be the set of the given alternatives and let U be the set of alternatives that are not given and have the same parent as the given alternatives. Let M be all alternatives in U that are positioned between two alternatives T. As long as the relative order of the alternatives in M is preserved, all permutations of T ∪ M are guaranteed to be have equivalently.

    Note that this function makes no guarantees about the alternative U \ (T ∪ M). Permutations that change the position of those alternatives are not guaranteed to be valid.

    Example: /0|1|2|💚|3|4|💯|👋|5|6/ with T = 💚|💯|👋, U = 0|1|2|3|4|5|6, and M = 3|4.

    This function will return true and the following are guaranteed to be valid permutations:

    • /0|1|2|💚|3|4|💯|👋|5|6/ (unchanged)
    • /0|1|2|3|💚|4|💯|👋|5|6/
    • /0|1|2|3|4|💚|💯|👋|5|6/
    • /0|1|2|💚|💯|3|4|👋|5|6/
    • /0|1|2|💚|💯|👋|3|4|5|6/
    • /0|1|2|👋|💯|💚|3|4|5|6/
    • /0|1|2|👋|3|4|💯|💚|5|6/

    The following are not guaranteed to be valid permutations:

    • /0|1|2|💚|4|3|💯|👋|5|6/ (3 and 4 were swapped)
    • /💚|0|1|2|3|4|💯|👋|5|6/ (the position of 0 was changed)
    • /0|1|2|💚|3|4|👋|5|6|💯/ (the position of 6 was changed)

    Parameters

    Returns boolean