Files
habitica/common/script/fns/randomVal.js
T
Blade Barringer 0a7b6b65e7 Revert "API v3 [WIP] (#6144)"
This reverts commit 28f2e9c356.
2016-05-23 07:53:14 -05:00

15 lines
405 B
JavaScript

import _ from 'lodash';
/*
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);
array.sort();
return array[Math.floor(rand * array.length)];
};