Last change
on this file since 3148 was
3148,
checked in by mylan, 14 years ago
|
Added selection of random 5 elements from the submissions topic
|
-
Property svn:eol-style set to
native
|
File size:
715 bytes
|
Line | |
---|
1 | function getRandomSubset(array, choice_num) { |
---|
2 | // Return randomly selected *choice_num* elements from the array |
---|
3 | var tmp, current, top = array.length; |
---|
4 | if (array.length > choice_num) { |
---|
5 | // random elements places to the end of the array |
---|
6 | for(top=array.length-1; top>array.length-choice_num; --top) { |
---|
7 | current = Math.floor(Math.random() * top); |
---|
8 | tmp = array[current]; |
---|
9 | array[current] = array[top]; |
---|
10 | array[top] = tmp; |
---|
11 | } |
---|
12 | return array.slice(array.length-choice_num,array.length) |
---|
13 | } else { |
---|
14 | return array; |
---|
15 | } |
---|
16 | }; |
---|
17 | |
---|
18 | $(document).ready(function() { |
---|
19 | $(getRandomSubset($("#portal-bounty-program ul li"), 5)) |
---|
20 | .each(function(){ |
---|
21 | $(this).removeClass('hidden'); |
---|
22 | }) |
---|
23 | }); |
---|
Note: See
TracBrowser
for help on using the repository browser.