28 lines
785 B
TypeScript
28 lines
785 B
TypeScript
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
import random from "../random/random.ts";
|
|
import numbers from "./numbers.ts";
|
|
|
|
export default class arrays {
|
|
/**
|
|
* 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 = numbers.tiny()) {
|
|
const array = []
|
|
|
|
for (let i = 0; i < limit; i++) {
|
|
const value = random.pick(fn)
|
|
if (value !== null) {
|
|
array.push(value)
|
|
}
|
|
}
|
|
|
|
return array
|
|
}
|
|
}
|
|
|