Refactor make.arrays.filledArray

This commit is contained in:
pyoor 2018-08-20 12:20:36 -04:00
parent 68c606d0dd
commit 946e322406

View file

@ -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)
}
}