<script type="text/javascript"> function foo( a ) { var p = []; for ( var i = 1, n = 1; n < a * 2; n < a ? i++ : i--, n++ ) { p.push( i ); } return p; } document.write( foo( 10 ) ); </script>