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.119 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.118 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.117 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.116 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.115 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.114 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.113 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.111 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.110 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.109 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.108 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.107 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.106 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.105 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.104 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.103 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.102 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.101 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.100 tracks/javascript/exercises/collatz-conjecture/example.js
trackler-2.2.1.99 tracks/javascript/exercises/collatz-conjecture/example.js