Skip to content

stockArray

Jason Godesky edited this page Jul 11, 2026 · 1 revision

stockArray stocks an array with a number of values.

Tip

A common use pattern is to use stockArray to “put things in the hat” and selectRandomElement to “pull one out of the hat.”

Parameters

stock: Array<{ n: number, item: T }>

An array of objects. For each object, n sets the number of times that item should be added to the array.

Returns

A new array created according to the directions from stock.

Examples

import { stockArray } from '@revolutionarygamesco/common'

const stock: Array<{ n: number, item: boolean }> = [
  { n: 2, item: false },
  { n: 1, item: true }
]

stockArray<boolean>(stock) // [false, false, true] 

See also

Clone this wiki locally