Sha256: c211b70ba4a8eb27a8984e81a749dbea8f1feffb1c2484b327aad65f006e1799

Contents?: true

Size: 453 Bytes

Versions: 132

Compression:

Stored size: 453 Bytes

Contents

'use strict';

function CollatzConjecture() {}

CollatzConjecture.prototype.steps = function (number) {
  var count = 0;
  if (number < 1) {
    throw new Error('Only positive numbers are allowed');
  }
  getStepsCount(number);
  function getStepsCount(n) {
    if (n === 1) return 0;
    var nextNumber = ( n % 2 === 0 ? n / 2 : 3 * n + 1);
    count++;
    return getStepsCount(nextNumber);
  }
  return count;
};

module.exports = CollatzConjecture;

Version data entries

132 entries across 132 versions & 1 rubygems

Version Path
trackler-2.2.1.98 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.97 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.96 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.95 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.94 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.93 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.92 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.91 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.90 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.89 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.88 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.87 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.86 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.85 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.84 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.83 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.82 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.81 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.80 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.79 tracks/javascript/exercises/collatz-conjecture/example.js