Merge pull request from technoboy10/gh123-randomize-rows

Fix GH-123: Shuffle top loved and top remixed
This commit is contained in:
Connor Hudson 2016-06-13 10:38:18 -04:00 committed by GitHub
commit d7c78bd234
2 changed files with 26 additions and 2 deletions
src
lib
views/splash

21
src/lib/shuffle.js Normal file
View 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;
};

View file

@ -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>
);