Sha256: 8598f66bdd88ac47c42c428756dc62c76a8aa5669af238e5c4378e5a5fc7f155

Contents?: true

Size: 409 Bytes

Versions: 105

Compression:

Stored size: 409 Bytes

Contents

'use strict';

module.exports = Trinary;

var BASE = 3;

function Trinary(decimal) {
  this.digits = decimal.split('').reverse().map(Number);
}

Trinary.prototype.toDecimal = function () {
  var decimal = this.digits.reduce(this.accumulator, 0);
  return isNaN(decimal) ? 0 : decimal;
};

Trinary.prototype.accumulator = function (decimal, digit, index) {
  return decimal + digit * Math.pow(BASE, index);
};

Version data entries

105 entries across 105 versions & 1 rubygems

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