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')
|
const random = require('../random')
|
||||||
|
|
||||||
class arrays extends make {
|
class arrays extends make {
|
||||||
static filledArray (fn, limit) {
|
/**
|
||||||
let array = []
|
* Returns an array containing random values generated by the supplied function
|
||||||
let size = limit || random.number(make.number.tiny()) + 1
|
* @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++) {
|
for (let i = 0; i < limit; i++) {
|
||||||
let value = random.pick(fn)
|
const value = random.pick(fn)
|
||||||
if (value !== undefined) {
|
if (value !== null) {
|
||||||
array.push(value)
|
array.push(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue