// title: List expander and contractor function // author: moncrey // description: // useful for expanding or reducing arrays by 2^x. // I would like to know if there is a more concise way to write this! // Any suggestions? // // (duplicate post, sorry! forgot to log in!) // code: ( b = {|x,y| var arr = List[]; case {y % x.size == 0} // condition 1 { var per = y / x.size; x.size.do{|oo| var pp = 1,i = 1; arr.add( x[oo] ); while({i < per},{ arr.add(0); i = i+1; }); } } {x.size % y == 0} // condition 2 { var pp = x.size / y, i = 0, sz = x.size; while({i < sz},{ if(i % pp == 0) { arr.add(x[i]) }; i=i+1; }); }; arr }; a = [1,1,1,1]; c = b.value(a,16) // [ 1, 1, 1, 1 ] // becomes // [ 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 ] b.value(c,4); // [ 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 ] // becomes // [ 1, 1, 1, 1 ] )