mercredi 2 décembre 2020

I have an array of objects. I want to randomly output objects whose sum of values ​is equal to eight

    
const obj = 
    [
        {noir: 1},
        {croch: 0.5},
        {doubleCroch: 1},
        {triollet: 1.5},
        {quatreDouble: 2} 

    
];


desired output example:

2, 2, 0.5, 0.5, 1, 2

 for (var i = 0 ; i < obj.length ; i++ ){
        var randomItem = obj[Math.floor(Math.random()*obj.length )];
        
    }


That brings me five random items. But I want to have elements whose sum of values ​​is equal to eight.

It looks like a condition inside the random




Aucun commentaire:

Enregistrer un commentaire