Refactor make.arrays.filledArray
This commit is contained in:
parent
68c606d0dd
commit
946e322406
1 changed files with 11 additions and 6 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue