09-19-2024 06:04 AM
Hello
I have the array followed with these values and I need to filter these values by comparing the id value
In this case, I need to find the values closest to 1499 and the indices of these values (In this case they are 1500... 1554). In my application, all of these input values are dynamic, they are not fixed at these values.
Could you help me to do that?
Solved! Go to Solution.
09-19-2024 06:18 AM - edited 09-19-2024 06:21 AM
Hi Leandro,
@leandrofeder wrote:
I need to find the values closest to 1499 and the indices of these values (In this case they are 1500... 1554).
There is only one value "closest" to 1499 and that is 1500… (Well, maybe there could be 2 values closest to target with the same distance, unless there could be more then one array element with the same value.)
Maybe you should start with defining your problem in a more accurate way?
@leandrofeder wrote:
In my application, all of these input values are dynamic, they are not fixed at these values.
Could you help me to do that?
Yes: use conditional output tunnels in your loop to keep only the values/indices of interest!
Other suggestion: instead of strings you should work with integer data. Atleast you could convert from string to numeric value once before the loop…
09-19-2024 06:46 AM
It's just that all the data I'm receiving comes from a string, the previous treatment I didn't put here because it's not necessary.
I adopted the conversion suggestion before the loop.
But basically my application searches for data from a place and returns an array with several numbers, these numbers must be subsequent to 1499 (in this case), then I would have to filter the array and search only 1500, 1550, 1551, 1552, 1553, 1554. Which are the closest values to 1499 compared to the rest of the array
09-19-2024 07:06 AM
A small change to your code will get you what you need
09-19-2024 08:15 AM - edited 09-19-2024 08:18 AM
@leandrofeder wrote:
I just want to point out why this will never work: you have the min and max reversed.
As it is, the range is >=1599 and <1500. That won't work: no number is smaller than 1500 and larger or equal than 1599.
The coercion will work, but the in range output will always be false!
The range needs to be reversed.
I highly recommend you convert the strings to numbers as soon as possible. It's absolutely horrible to keep all data as strings, just because they came from a query or file or listbox, ring, etc..
Being able to see integers as integers, doubles as doubles, etc. will help you a lot in the long run.