Sha256: 466a17b5428dabc65dac2988d91dcbf9d61196d5c15c70f5d70c76fb7138ce69

Contents?: true

Size: 969 Bytes

Versions: 211

Compression:

Stored size: 969 Bytes

Contents

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

class SpaceAge {

  constructor(seconds) {
    this.seconds = seconds;
    this.earthYears = seconds / 31557600;
  }

  yearsOnPlanet(planet) {
    const years = this.earthYears / EARTH_TO_OTHER_PLANETS[planet];
    return parseFloat(years.toFixed(2));
  }

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

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

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

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

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

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

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

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

}

export default SpaceAge;

Version data entries

211 entries across 211 versions & 1 rubygems

Version Path
trackler-2.2.0.0 tracks/ecmascript/exercises/space-age/example.js
trackler-2.1.0.55 tracks/ecmascript/exercises/space-age/example.js
trackler-2.1.0.54 tracks/ecmascript/exercises/space-age/example.js
trackler-2.1.0.53 tracks/ecmascript/exercises/space-age/example.js
trackler-2.1.0.52 tracks/ecmascript/exercises/space-age/example.js
trackler-2.1.0.51 tracks/ecmascript/exercises/space-age/example.js
trackler-2.1.0.50 tracks/ecmascript/exercises/space-age/example.js
trackler-2.1.0.49 tracks/ecmascript/exercises/space-age/example.js
trackler-2.1.0.48 tracks/ecmascript/exercises/space-age/example.js
trackler-2.1.0.47 tracks/ecmascript/exercises/space-age/example.js
trackler-2.1.0.46 tracks/ecmascript/exercises/space-age/example.js
trackler-2.1.0.45 tracks/ecmascript/exercises/space-age/example.js
trackler-2.1.0.44 tracks/ecmascript/exercises/space-age/example.js
trackler-2.1.0.43 tracks/ecmascript/exercises/space-age/example.js
trackler-2.1.0.42 tracks/ecmascript/exercises/space-age/example.js
trackler-2.1.0.41 tracks/ecmascript/exercises/space-age/example.js
trackler-2.1.0.40 tracks/ecmascript/exercises/space-age/example.js
trackler-2.1.0.39 tracks/ecmascript/exercises/space-age/example.js
trackler-2.1.0.38 tracks/ecmascript/exercises/space-age/example.js
trackler-2.1.0.37 tracks/ecmascript/exercises/space-age/example.js