All files / src/utils getMask.js

100% Statements 9/9
100% Branches 4/4
100% Functions 1/1
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46    2x                   2x         2x 22x 3x     19x           19x 27x     19x                          
import R from 'ramda'
 
export const getRandomMask = R.pipe(
  R.range(0),
  R.map(
    R.pipe(
      Math.random,
      Math.round
    )
  )
)
 
export const getFullMask = R.pipe(
  R.range(0),
  R.map(R.always(1))
)
 
export const getForwardMask = (length, roll = length, count = roll) => {
  if (count <= 1) {
    return R.repeat(1, length)
  }
 
  const base = R.pipe(
    R.divide,
    Math.floor,
    R.repeat(R.__, length)
  )(roll, length)
 
  for (let i = 0; i < roll % length; i++) {
    base[i]++
  }
 
  return R.pipe(
    R.scan(R.add, 0),
    R.findIndex(R.lt(roll - count)),
    R.juxt([
      R.repeat(1),
      R.pipe(
        R.subtract(length),
        R.repeat(0)
      ),
    ]),
    R.flatten
  )(base)
}