An array is created from external sensors and that array is constrained to a scale.
Here's the sample code:
(
~weight = 70;
~array = ((~weight - 12) .. ~weight);
l = Scale.majorPentatonic.degrees; // pentatonic scale
j = (~array).collect { |i| i.nearestInScale(l, 12)}
)
This produces an array, but repeats notes that it matches to the scale, for example:
[ 57, 57, 60, 62, 62, 64, 64, 64, 67, 67, 69, 69, 69 ]
How do I filter this array to only unique values so it looks like this:
[ 57, 60, 62, 64, 67, 69 ]
j.as(Set).as(Array).sort;
You can convert the Array to a Set and back again to remove the duplicate items. Set is an unordered collection so you will have to sort the new array in order to get the result you are after.