const Benchmark = require('benchmark')
const BigNumber = require('decimal.js')
const padRight = require('pad-right')
function pad (text) {
  return padRight(text, 40, ' ')
}

const results = []

function bigFactorial (n) {
  if (n.isZero()) {
    return new BigNumber(1) // 0! is per definition 1
  }

  let res = new BigNumber(n)
  let value = n.toNumber() - 1 // number
  while (value > 1) {
    res = res.times(value)
    value--
  }

  return new BigNumber(res)
}

function betterFactorial(n) {
  if(n % 2 === 1) {
    return n.times(betterFactorial(new BigNumber(n - 1)));
  }

  let p = n;
  let prod = n;
  let sum = n.toNumber();

  while(p > 2) {
    p -= 2;
    sum += p;
    prod = prod.times(sum);
  }

  return prod;
}

console.log('factorial 5 ' + bigFactorial(new BigNumber(6)))
console.log('new factorial 5 ' + betterFactorial(new BigNumber(6)))

const suite = new Benchmark.Suite()
suite
  .add(pad('bigFactorial for small numbers'), function () {
    const res = bigFactorial(new BigNumber(8))
    results.push(res)
  })
  .add(pad('new bigFactorial'), function () {
    const res = betterFactorial(new BigNumber(8));
    results.push(res)
  })
  .add(pad('bigFactorial for big numbers'), function () {
    const res = bigFactorial(new BigNumber(600))
    results.push(res)
  })
  .add(pad('new bigFactorial for big numbers'), function () {
    const res = betterFactorial(new BigNumber(600));
    results.push(res)
  })
  .on('cycle', function (event) {
    console.log(String(event.target))
  })
  .on('complete', function () {
  })
  .run()

@@ -486,16 +486,17 @@
 actorial
+ 
 (n) %7B%0A  
@@ -497,16 +497,17 @@
 ) %7B%0A  if
+ 
 (n %25 2 =
@@ -571,17 +571,16 @@
 n - 1)))
-;
 %0A  %7D%0A%0A  
@@ -584,25 +584,24 @@
 %0A  let p = n
-;
 %0A  let prod 
@@ -603,17 +603,16 @@
 prod = n
-;
 %0A  let s
@@ -628,17 +628,16 @@
 Number()
-;
 %0A%0A  whil
@@ -637,16 +637,17 @@
 %0A  while
+ 
 (p %3E 2) 
@@ -658,17 +658,16 @@
   p -= 2
-;
 %0A    sum
@@ -671,17 +671,16 @@
 sum += p
-;
 %0A    pro
@@ -698,17 +698,16 @@
 mes(sum)
-;
 %0A  %7D%0A%0A  
@@ -717,17 +717,16 @@
 urn prod
-;
 %0A%7D%0A%0Acons
@@ -1122,17 +1122,16 @@
 mber(8))
-;
 %0A    res
@@ -1401,9 +1401,8 @@
 00))
-;
 %0A   

Fix linting issues (see PR #1690)