wip(shared): port buy ops and linked fns

This commit is contained in:
Matteo Pagliazzi
2016-03-16 16:25:46 +01:00
parent e68ebee980
commit ff72706cae
11 changed files with 227 additions and 215 deletions

View File

@@ -1,14 +1,12 @@
import _ from 'lodash';
import predictableRandom from './predictableRandom';
/*
Get a random property from an object
returns random property (the value)
*/
// Get a random property from an object
// returns random property (the value)
module.exports = function(user, obj, options) {
var array, rand;
array = (options != null ? options.key : void 0) ? _.keys(obj) : _.values(obj);
rand = user.fns.predictableRandom(options != null ? options.seed : void 0);
module.exports = function randomVal (user, obj, options = {}) {
let array = options.key ? _.keys(obj) : _.values(obj);
let rand = predictableRandom(user, options.seed);
array.sort();
return array[Math.floor(rand * array.length)];
};