mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
wip(shared): port buy ops and linked fns
This commit is contained in:
@@ -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)];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user