const getRandomNumber = ( min , max ) => Math . floor ( Math . random ( ) * ( max - min + 1 ) ) + min ; function getRandomItem < T > ( arr ) { return arr [ getRandomNumber ( 0 , arr . length - 1 ) ] ; } const getMilisecondsFromSeconds = ( seconds ) : number => seconds * 1000 ; const probability = ( chance ) : boolean => getRandomNumber ( 0 , 100 ) <= chance ; const waitFor = ( timeout ) : Promise < void > => new Promise ( resolve => { setTimeout ( resolve , timeout ) ; } ) ; function reduceAsync < T , R > ( arr , fn , waitForSeconds , startValue = undefined ) { return Promise . resolve ( arr . reduce ( async ( prev , curr , index ) => { const result = await prev ; await waitFor ( getMilisecondsFromSeconds ( waitForSeconds ) ) ; return Promise . resolve ( fn ( result , curr , index ) ) ; } , Promise . resolve ( startValue ) ) ) ; } export { getRandomItem , getMilisecondsFromSeconds , probability , waitFor , reduceAsync , getRandomNumber , } ;