dimanche 5 avril 2020

number of elements on array

this is my first time asking something here, so sorry about any mistakes.... Well...I have an array with 30 values that will be randomly distributed between other 3 arrays... I made it work "almost" right... but the 3 arrays always come with a random quantity of elements and I need 2 of them with 8 elements and other with 14.... how can i define that?

            const arrAll = [s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10]
            const arrCard = []
            const arrCent = []
            const arrSec = []

            arrAll.map(l => {
                let rand = Math.floor(Math.random() * 9000)
                rand <= 3000 ? arrCard.push(l) : rand <= 6000 ? arrCent.push(l) : arrSec.push(l);
            })



Aucun commentaire:

Enregistrer un commentaire