From 946e3224064a57e51aa5edc61383208c19082463 Mon Sep 17 00:00:00 2001 From: pyoor Date: Mon, 20 Aug 2018 12:20:36 -0400 Subject: [PATCH] Refactor make.arrays.filledArray --- lib/make/arrays.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/make/arrays.js b/lib/make/arrays.js index 639461e..0d05fb6 100644 --- a/lib/make/arrays.js +++ b/lib/make/arrays.js @@ -6,13 +6,18 @@ const make = require('../make') const random = require('../random') class arrays extends make { - static filledArray (fn, limit) { - let array = [] - let size = limit || random.number(make.number.tiny()) + 1 + /** + * Returns an array containing random values generated by the supplied function + * @param {Function} fn - Function used to generate values + * @param {number} limit - Length of the array + * @returns {Array} + */ + static filledArray (fn, limit = make.number.tiny()) { + const array = [] - for (let i = 0; i < size; i++) { - let value = random.pick(fn) - if (value !== undefined) { + for (let i = 0; i < limit; i++) { + const value = random.pick(fn) + if (value !== null) { array.push(value) } }