Jump to content
Sign in to follow this  
Grumpy Old Man

Array value sorting - another issue

Recommended Posts

Hey folks

this one is really tough for me,

lets say I have an array like _array1 = [24.37,24.38,24.40,42.44,42.45,87.21,87.22]

as you can see it's already sorted in ascending order

how can I sort it further so that values that are very close together (like 87.21 and 87.22 as an example) are being put into a new array?

Cheers

Share this post


Link to post
Share on other sites

//sort numbers from lowest to highest
_sortedNumbers = [[1,-80,0,480,15,-40],[],{_x},"ASCEND"] call BIS_fnc_sortBy;

This can sort your array. How close do you want the values to be to make another Array? Try looking into "BIS_fnc_subSelect".

Share this post


Link to post
Share on other sites

Hey Johnson11B2P,

my array was already sorted, I just wanted to filter out values that are close together and put them in a new array,

when looking for BIS_fnc_subSelect I stumbled across BIS_fnc_conditionalSelect which looks like it's doing what I need.

Cheers

Share this post


Link to post
Share on other sites

my array was already sorted, I just wanted to filter out values that are close together and put them in a new array,

Given your input (_array1) is already sorted (no matter if ascending or descending; doesn't matter), you can do something like this to filter values that are sitting to close to each other:

 

_array1 = [24.37,24.38,24.40,42.44,42.45,87.21,87.22];
_threshold = 0.5;
_filtered = [];
_last = -1;
{
   if (_forEachIndex == 0) then
   {
      _filtered pushBack _x;
      _last = _x;
   } else {
      _diff = abs (_x - _last);
      if (_diff >= _threshold) then
      {
         _filtered pushBack _x;
         _last = _x;
      }
   }
} forEach _array1;

// use/return _filtered
This is absolutely untested B) , but you get the idea. Have some threshold and keep track of the last value you've pushed back, then you can simply compute the difference between the next potential value and the last one pushed back and see if it's larger than the defined threshold.

Share this post


Link to post
Share on other sites

After two years I hope Grumpy had it figured out already! ^^

  • Like 1

Share this post


Link to post
Share on other sites

After two years I hope Grumpy had it figured out already! ^^

bwahaha, haven't noticed the necrobump.

  :rolleyes:

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×