Sha256: aa43803cbed56654257cd610b959116195c1db26cb17688bfad9fd3c09846054

Contents?: true

Size: 536 Bytes

Versions: 104

Compression:

Stored size: 536 Bytes

Contents

'use strict';

var BASE = 8;

function Octal(octal) {
  this.digits = octal.split('').reverse().map(this.digitValue);
}

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

Octal.prototype.digitValue = function (value) {
  var result = Number(value);
  return (result < BASE) ? result : Number.NaN;
};

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

module.exports = Octal;

Version data entries

104 entries across 104 versions & 1 rubygems

Version Path
trackler-2.2.1.119 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.118 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.117 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.116 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.115 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.114 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.113 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.111 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.110 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.109 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.108 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.107 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.106 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.105 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.104 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.103 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.102 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.101 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.100 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.99 tracks/javascript/exercises/octal/example.js