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.180 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.179 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.178 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.177 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.176 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.175 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.174 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.173 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.172 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.171 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.170 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.169 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.167 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.166 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.165 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.164 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.163 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.162 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.161 tracks/javascript/exercises/octal/example.js
trackler-2.2.1.160 tracks/javascript/exercises/octal/example.js