trymnilsen / kingdomarchitect

Medieval simulation/city builder game for the browser.
https://kingdomarchitect.netlify.app
MIT License
13 stars 2 forks source link

Return null or undefined if array size is 0 #173

Closed github-actions[bot] closed 4 weeks ago

github-actions[bot] commented 4 weeks ago

https://github.com/trymnilsen/kingdomarchitect/blob/b709b7e6d1bb27f0fd76d52b2a77856c4e0e10d6/ts/src/common/array.ts#L8


 */
export function randomEntry<T>(array: T[]): T {
    const randomIndex = Math.floor(Math.random() * array.length);
    // TODO: Return null or undefined if array size is 0
    return array[randomIndex];
}
github-actions[bot] commented 4 weeks ago

Closed in b6feb1f0e502d17ba226d7bfedbf2ff157459878.