create a list of the last n values (or anything else)

Aug 23, 2007 at 9:37am

create a list of the last n values (or anything else)

Hi,

Here is the javascript code of a simple function that outputs a list of the last n values (specified in the argument, such as “js list 10″), every time it receives a new value.

I struggled to find a way of doing that with “zl” so I wrote this simple code.

I thought it might be useful to some, so here is the code (also attached):

var size_list = jsarguments[1];

var t = new Array(size_list);
var t_sorted = new Array(size_list);
var pos = 0;

function anything(v)
{
t[pos] = v;

for (var i = 0; i < size_list ; i++)
t_sorted[i] = t[(pos+1+i)%size_list];

pos = (pos+1)%size_list;
outlet(0,t_sorted);
}

best
Jean-Baptiste

#33377
Aug 23, 2007 at 2:00pm

#111173
Aug 31, 2007 at 8:14am

Jean-Baptiste Thiebaut schrieb:
> I struggled to find a way of doing that with “zl”

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#N vpatcher 536 351 813 611;
#P window setfont “Sans Serif” 9.;
#P window linecount 0;
#P newex 178 34 63 196617 patcherargs;
#P message 181 101 38 196617 zlclear;
#P newex 181 77 38 196617 sel 1;
#P newex 146 76 25 196617 – 1;
#P window linecount 1;
#P newex 50 196 41 196617 zl rev;
#P newex 50 54 41 196617 t l b;
#P newex 113 124 43 196617 – 1;
#P newex 113 102 34 196617 zl len;
#P newex 81 76 36 196617 zl reg;
#P newex 50 170 41 196617 zl join;
#P newex 81 145 42 196617 zl ecils;
#P inlet 50 34 15 0;
#P inlet 146 34 15 0;
#P outlet 50 218 15 0;
#P connect 2 0 8 0;
#P fasten 12 0 4 0 186 166 55 166;
#P connect 8 0 4 0;
#P connect 4 0 9 0;
#P connect 9 0 0 0;
#P connect 8 1 5 0;
#P connect 5 0 3 0;
#P connect 3 0 4 1;
#P fasten 4 0 5 1 55 191 177 191 177 71 112 71;
#P fasten 5 0 6 0 86 97 118 97;
#P connect 6 0 7 0;
#P connect 7 0 3 1;
#P connect 1 0 10 0;
#P connect 10 0 7 1;
#P connect 1 0 11 0;
#P connect 11 0 12 0;
#P pop;
#P newobj 124 121 49 196617 p lastnl;
#P message 124 176 99 196617 88;
#P newex 124 153 62 196617 prepend set;
#P number 163 67 35 9 1 0 1 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 124 67 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P connect 0 0 4 0;
#P connect 1 0 4 1;
#P connect 4 0 2 0;
#P connect 2 0 3 0;
#P window clipboard copycount 5;


Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
– _|_)—-|—–()————–
———-()——–www.ccmix.com

#111174
Sep 1, 2007 at 2:03pm

Hi,
Here’s one of the externals I’m developping for SIlex creations inc, a
compagny specialized in speech synthesis and recognition.

You need to put as argument the “n” in “the last n-elements”.

Works with float and int. Next version will work with symbols too.

Our library of machine learning (useful for gesture recognition with
the Wii) is coming quite soon. Stay tune…

PC

#111175
Sep 1, 2007 at 4:49pm

#111176

You must be logged in to reply to this topic.