I have one number array like below picture.
I'd like to remove whole minus numbers and duplicate numbers, and sort the array in ascending order, like below.
How could I do that?
Unless there was a real efficiency need, I'd shoot for simplicity and readability:
You could always AND the >0 and != tests together and wire that directly to the concatenation terminal.
The output array from the for loop will be what you're looking for.
I like Vivien's use of Threshold 1D Array
and Array Subset
to remove the negative values, but the rotate and subtract before removing zeroes seems unnecessarily complex. Here's a solution with a For
loop, shift register and conditional indexing:
Note that we have to initialise the shift register with something, or it would remember data from the previous run, giving unwanted behaviour (the same would be true of a feedback node) - so we make sure that the first array element will always be included by ensuring that the initialisation value is not equal to the first element.
This does the job :