split user.fns

This commit is contained in:
Matteo Pagliazzi
2016-03-08 18:58:39 +01:00
parent 393a26e51a
commit bb6f0f4252
21 changed files with 808 additions and 704 deletions

View File

@@ -0,0 +1,14 @@
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)];
};