You could add the indices to each array:a = [0.4, 0.42, 0.45, 0.46, 0.6, 0.7];a = a.collect({|item, i| [item, i]});b = a.separate { |a, b| (b[0] - a[0]) >= 0.02 };
On November 30, 2019 at 6:56:32 PM, jables.deutsch@xxxxxxxxx (jables.deutsch@xxxxxxxxx) wrote:
Thanks, Newton -
Is there any way to preserve the indices, like the "order" method does, also?
On Sat, Nov 30, 2019 at 4:29 AM Armstrong, Newton <Newton.Armstrong.1@xxxxxxxxxx> wrote:a = [0.4, 0.42, 0.45, 0.46, 0.6, 0.7];
b = a.separate { |a, b| (b - a) >= 0.02 };
> On 30 Nov 2019, at 6:15am, jables.deutsch@xxxxxxxxx wrote:
>
> Hi all -
>
> I'd like to take an array and break it into sub-arrays, based on the difference between values.. It might be easier to illustrate:
>
> I have an array:
> a = [0.4, 0.42, 0.45, 0.46, 0.6, 0.7];
> And I want to set a threshold of difference - in this case: 0.02.
> newArray = [[0.4, 0.42], [0.45, 0.46], [0.6], [0.7]];
>
> Is there a function that does this kind of sorting intrinsically? Can anyone suggest an approach?
>
>
>
>
>
_______________________________________________
sc-users mailing list
info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: https://listarc.bham.ac.uk/marchives/sc-users/
search: https://listarc.bham.ac.uk/lists/sc-users/search/