Sha256: 5a21d7b8c2e5128d4974cb59974e6dcaf04b9954258a9e0773ba70283f440690

Contents?: true

Size: 1.12 KB

Versions: 141

Compression:

Stored size: 1.12 KB

Contents

function SpaceAge(seconds) {
  'use strict';

  this.seconds = seconds;
  this.earthYears = seconds / 31557600;

  this.earthToOtherPlanets = {
    mercury: 0.2408467,
    venus: 0.61519726,
    earth: 1,
    mars: 1.8808158,
    jupiter: 11.862615,
    saturn: 29.447498,
    uranus: 84.016846,
    neptune: 164.79132
  };

  this.yearsOnPlanet = function (planet) {
    var years = this.earthYears / this.earthToOtherPlanets[planet];
    return parseFloat(years.toFixed(2));
  };

  this.onMercury = function () {
    return this.yearsOnPlanet('mercury');
  };

  this.onVenus = function () {
    return this.yearsOnPlanet('venus');
  };

  this.onEarth = function () {
    return this.yearsOnPlanet('earth');
  };

  this.onMars = function () {
    return this.yearsOnPlanet('mars');
  };

  this.onJupiter = function () {
    return this.yearsOnPlanet('jupiter');
  };

  this.onSaturn = function () {
    return this.yearsOnPlanet('saturn');
  };

  this.onUranus = function () {
    return this.yearsOnPlanet('uranus');
  };

  this.onNeptune = function () {
    return this.yearsOnPlanet('neptune');
  };
}

module.exports = SpaceAge;

Version data entries

141 entries across 141 versions & 1 rubygems

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