주사위 굴리기

Nekoromancer·2021년 12월 30일
0
// Library: Lodash/fp
import fp from "https://cdn.skypack.dev/lodash@4.17.21/fp";

const dice = fp.curry((phase, mod, times) => {
  return new Array(times)
    .fill(0)
    .map(() => fp.random(1, phase))
    .reduce((result, trial) => result + trial, mod || 0);
}, 2);

// n d 6 + 1
const d6Plus1 = dice(6, 1);

// 1 d 6 + 1
d6Plus1(1);

// 3 d 6 + 1
d6Plus1(3);
profile
고양이 앓이 중인 프론트엔드 개발자

0개의 댓글