ビンゴの結果を整形表示
Posted feedbacks - JavaScript
ブラウザとCScriptに対応。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Array.prototype.$huffle = function(){
for(var $, r, i = this.length; i;)
$ = this[r = Math.random() * i-- | 0], this[r] = this[i], this[i] = $;
return this;
};
function bingo(n, w){
if(!w) w = 10;
for(var a = [], i = 1; i <= n;) a[a.length] = i++;
var b = a.concat().$huffle(), r = [], l = (' '+ n).length;
while(a.length) r[r.length] = a.splice(0, w).join(' ') +'\n'+ b.splice(0, w).join(' ');
r = r.join('\n\n').replace(/ *\d+/g, function($){ while($.length < l) $ = ' '+ $; return $ });
if(typeof WSH != 'undefined') WSH.stdOut.write(r);
else document.write('<pre>'+ r +'</pre>');
}
|

raynstard
#3403()
Rating1/1=1.00
「重複無し乱数」で作ったbingo関数の結果を下のように「何番目の乱数か」とセットにして10個ずつ折り返して表示するコードを書いてください。
[ reply ]