move to feature module and init board

This commit is contained in:
Julien Calixte
2023-07-22 11:42:54 +02:00
parent 2d9006b4c9
commit 835e0cf642
9 changed files with 77 additions and 16 deletions

View File

@@ -10,3 +10,23 @@ export const shuffleArray = <T>(array: T[]) => {
return arrayCopy
}
export const popNElement = <T>(array: T[], numberOfElements: number) => {
const poppedElements: T[] = []
for (let i = 0; i < numberOfElements; i++) {
const element = array.pop()
if (element) {
poppedElements.push(element)
}
}
return poppedElements
}
export const pickRandomIndex = <T>(array: T[]) =>
Math.floor(Math.random() * array.length)
export const pickRandomElement = <T>(array: T[]) =>
array[pickRandomIndex(array)]