isperm

isperm(v) -> Bool

Returns true if v is a valid permutation.

Examples

  1. Check if an array is a valid permutation:

    julia> isperm([2, 1, 3])
    true

    This example returns true because [2, 1, 3] is a valid permutation.

  2. Handle edge cases with repeated elements:

    julia> isperm([1, 2, 2])
    false

    It returns false because [1, 2, 2] is not a valid permutation due to the repeated element 2.

  3. Check if a range is a valid permutation:
    julia> isperm(1:4)
    true

    It returns true because 1:4 is a valid permutation.

Common mistake example:

julia> isperm([3, 1, 4])
false

In this example, the array [3, 1, 4] is not a valid permutation because it does not contain the element 2. It's important to ensure that a valid permutation should include all elements from 1 to n, where n is the length of the collection.

See Also

all, all!, angle, any, any!, falses, ifelse, is, isinf, isinteger, isnan, isperm, ispow2, isreal, trues,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: