LCOV - code coverage report
Current view: top level - src/choose - choose.js (source / functions) Hit Total Coverage
Test: cov_profile.lcov Lines: 18 18 100.0 %
Date: 2021-12-16 00:47:58 Functions: 1 1 100.0 %
Branches: 3 3 100.0 %

           Branch data     Line data    Source code
       1                 :         16 : import chooser from "./chooser.js";
       2            [ + ]:         16 : 
       3                 :         16 : // TODO: can the choose method be improved? Can weights be defined as distribution instead?
       4                 :         16 : const choose = (seeded, qty, arr, { weights = [] } = {}) => {
       5                 :        182 :   const myArr = arr.slice(0);
       6                 :        182 :   const myWeightings = weights.slice(0);
       7                 :        182 :   return Array(qty || 0)
       8            [ + ]:        182 :     .fill(null)
       9                 :        182 :     .map(() => {
      10            [ + ]:        762 :       const index = chooser(seeded.random(), myArr, myWeightings);
      11                 :        762 :       const result = myArr[index];
      12                 :        762 :       myArr[index] = myArr[0];
      13                 :        762 :       myArr.shift();
      14                 :        762 :       return result;
      15                 :        182 :     });
      16                 :         16 : };
      17                 :         16 : 
      18                 :          8 : export default choose;

Generated by: LCOV version 1.15