Forums > Javascript

list wrangling

May 21, 2007 | 6:42 am

hi all, i also posted this in the max forum (sorry for the cross), but it occurred to me just now that my problem is probably pretty easy to solve in javascript. i’m a js newbie; can anybody help out?

i need to take a collection that has 2 associated elements: a buffer number (1-16) and a time in ms. the time values of each occurrence of each specific buffer need to be subtracted from the following occurrence of that same buffer, which would tell me how much time elapsed between them. then, if the time is less than a certain variable (say 2000ms) that index should be removed from the coll.

for example, if this is the coll

1, 1 1000;
2, 3 1600;
3, 1 1700;
4, 8 2000;
5, 3 3000;
6, 1 3500;
7, 3 3600;
8, 8 5000;

if would result in a list (or a coll) like this:

1 1000
3 1600
8 2000
1 3500
3 3600
8 5000

…where the buffer 1′s are kept only if they are far enough away from the other 1′s. same with 2′s, 3′s and so on.

many thanks,

jason


May 22, 2007 | 1:01 pm

Should be easy in js, but probably also slower than doing it with native max objects.

Could be a nice reason to start learning js though ;)

Mattijs

Quote: noxlux@yahoo.com wrote on Mon, 21 May 2007 08:42
—————————————————-
> hi all, i also posted this in the max forum (sorry for the cross), but it occurred to me just now that my problem is probably pretty easy to solve in javascript. i’m a js newbie; can anybody help out?
>
> i need to take a collection that has 2 associated elements: a buffer number (1-16) and a time in ms. the time values of each occurrence of each specific buffer need to be subtracted from the following occurrence of that same buffer, which would tell me how much time elapsed between them. then, if the time is less than a certain variable (say 2000ms) that index should be removed from the coll.
>
> for example, if this is the coll
>
> 1, 1 1000;
> 2, 3 1600;
> 3, 1 1700;
> 4, 8 2000;
> 5, 3 3000;
> 6, 1 3500;
> 7, 3 3600;
> 8, 8 5000;
>
> if would result in a list (or a coll) like this:
>
> 1 1000
> 3 1600
> 8 2000
> 1 3500
> 3 3600
> 8 5000
>
> …where the buffer 1′s are kept only if they are far enough away from the other 1′s. same with 2′s, 3′s and so on.
>
> many thanks,
>
> jason
>
>
—————————————————-


Viewing 2 posts - 1 through 2 (of 2 total)