You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert
debiru @ jsdo.it - share JavaScript, HTML5 and CSS - jsdo.itはブラウザでJavaScript,HTML5,CSSを書いて共有するサイト。他のコードをコピーして編集できます。JavaScript,HTML5,CSSに関する質問&回答もありますよ
真っ先に思いついたのはコレ。 function random(array, num) { var a = array.concat(); // clone. var r = []; var l = array.length; var n = Math.min(num, array.length); while(n-- > 0) { var i = Math.floor(Math.random() * l--); r.push(a[i]); a.splice(i, 1); } return r; } ランダムに1個取り出して、元の配列からそれを削除していくことで重複を避けるものです。 実際に使う分にはこれで全く問題ないと思うんですが、扱う数が大きくなってくると splice がボトルネックになってきます(LinkedListではないですからね)。 そこで、こう書き換えてみました。 funct
Searching with Array.prototype.some Aug 15, 2013 3 min read #javascript #optimization #tip Iterating over an array to search for an item is a pretty common task. With JavaScript, Array.prototype.forEach is often the popular choice. In some cases however, Array.prototype.some can be a better fit for the job if there is no need to search the entire array once a condition is fulfilled. There are at l
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く