I want to map the values of an array to a new array. The transformation should map arbitrary values in the original array to the value of the order in which that value was first observed.
For example, this mapping would map the first element of the array, x, to the value 1. All additional instances of x would be mapped to 1 as well. The next value in the array, y, would be mapped to the value 2. All additional instances of y would be mapped to 2 as well, and so on.
example:
array = [5 5 3 8 5 2 1 7 6 8 8 2 7 7 7 4];
new_array = [1 1 2 3 1 4 5 6 7 3 3 2 6 6 6 8];
another example:
array = [2 7 3 3 4 4 4 7 7 1 1 5 8 6 3 8 4 4 3 3 6 6];
new_array = [1 2 3 3 4 4 4 2 2 5 5 6 7 8 3 7 4 4 3 3 8 8];