Fill an array with unique elements

Any idea how to make sure an array does not contain duplicate elements efficiently? So convert array{1,2,3,3,3,4} into array{1,2,3,4}

Not sure about efficiency but this what i would do (first try)

    RemoveDuplicates(InArray:[]int) : []int =
        var MapSet : [int]logic = map{}

        OutArray := for:
            Value : InArray
            not MapSet[Value]?
            set MapSet[Value] = true
        do:
            Value

Then you use it like this:

        InArray := array{1,2,3,3,3,4,5,5,5,1}
        OutArray := RemoveDuplicates(InArray)
    
        for (Value : OutArray) { Print("{Value}") }
2 Likes

sick ty

This doesn’t answer the question directly, but in blueprints that’s what you use Sets for. You can easily convert them back to arrays.