mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2025-04-02 00:03:04 -04:00
Merge pull request #562 from technoboy10/gh123-randomize-rows
Fix GH-123: Shuffle top loved and top remixed
This commit is contained in:
commit
d7c78bd234
2 changed files with 26 additions and 2 deletions
src
21
src/lib/shuffle.js
Normal file
21
src/lib/shuffle.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Function that shuffles an array using a Fisher-Yates shuffle.
|
||||
*/
|
||||
|
||||
module.exports.shuffle = function (arr) {
|
||||
var i, j = 0;
|
||||
var temp = null;
|
||||
if (arr) {
|
||||
var tempArray = arr.slice(0);
|
||||
} else {
|
||||
return arr;
|
||||
}
|
||||
|
||||
for (i = arr.length - 1; i > 0; i -= 1) {
|
||||
j = Math.floor(Math.random() * (i + 1));
|
||||
temp = tempArray[i];
|
||||
tempArray[i] = tempArray[j];
|
||||
tempArray[j] = temp;
|
||||
}
|
||||
return tempArray;
|
||||
};
|
|
@ -5,6 +5,7 @@ var React = require('react');
|
|||
var render = require('../../lib/render.jsx');
|
||||
|
||||
var sessionActions = require('../../redux/session.js');
|
||||
var shuffle = require('../../lib/shuffle.js').shuffle;
|
||||
|
||||
var Api = require('../../mixins/api.jsx');
|
||||
|
||||
|
@ -308,7 +309,8 @@ var Splash = injectIntl(React.createClass({
|
|||
defaultMessage: 'What the Community is Remixing' })}
|
||||
key="community_most_remixed_projects">
|
||||
|
||||
<Carousel items={this.state.featuredGlobal.community_most_remixed_projects} showRemixes={true} />
|
||||
<Carousel items={shuffle(this.state.featuredGlobal.community_most_remixed_projects)}
|
||||
showRemixes={true} />
|
||||
</Box>,
|
||||
<Box title={
|
||||
formatMessage({
|
||||
|
@ -316,7 +318,8 @@ var Splash = injectIntl(React.createClass({
|
|||
defaultMessage: 'What the Community is Loving' })}
|
||||
key="community_most_loved_projects">
|
||||
|
||||
<Carousel items={this.state.featuredGlobal.community_most_loved_projects} showLoves={true} />
|
||||
<Carousel items={shuffle(this.state.featuredGlobal.community_most_loved_projects)}
|
||||
showLoves={true} />
|
||||
</Box>
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue