function funnyResize( arr, newElement, n )
{
n >>= 0; // убеждаемся что целове
if( n <= arr.length ) {
arr.length = n;
return arr;
}
n -= arr.length;
var elements = [ newElement ];
while( n > 1 ) {
if( n & 1 )
arr = arr.concat( elements );
elements = elements.concat( elements );
n >>= 1;
}
arr = arr.concat( elements );
return arr;
}
alert( funnyResize( ["A","A","A"], "B", 10 ) );