Sha256: b1503c5ecd45e19fc4c2d872da17dc2bab64849cfa6d4cf3916d68824a8d67e6

Contents?: true

Size: 970 Bytes

Versions: 185

Compression:

Stored size: 970 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

185 entries across 185 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/ecmascript/exercises/space-age/example.js
trackler-2.2.1.179 tracks/ecmascript/exercises/space-age/example.js
trackler-2.2.1.178 tracks/ecmascript/exercises/space-age/example.js
trackler-2.2.1.177 tracks/ecmascript/exercises/space-age/example.js
trackler-2.2.1.176 tracks/ecmascript/exercises/space-age/example.js
trackler-2.2.1.175 tracks/ecmascript/exercises/space-age/example.js
trackler-2.2.1.174 tracks/ecmascript/exercises/space-age/example.js
trackler-2.2.1.173 tracks/ecmascript/exercises/space-age/example.js
trackler-2.2.1.172 tracks/ecmascript/exercises/space-age/example.js
trackler-2.2.1.171 tracks/ecmascript/exercises/space-age/example.js
trackler-2.2.1.170 tracks/ecmascript/exercises/space-age/example.js
trackler-2.2.1.169 tracks/ecmascript/exercises/space-age/example.js
trackler-2.2.1.167 tracks/ecmascript/exercises/space-age/example.js
trackler-2.2.1.166 tracks/ecmascript/exercises/space-age/example.js
trackler-2.2.1.165 tracks/ecmascript/exercises/space-age/example.js
trackler-2.2.1.164 tracks/ecmascript/exercises/space-age/example.js
trackler-2.2.1.163 tracks/ecmascript/exercises/space-age/example.js
trackler-2.2.1.162 tracks/ecmascript/exercises/space-age/example.js
trackler-2.2.1.161 tracks/ecmascript/exercises/space-age/example.js
trackler-2.2.1.160 tracks/ecmascript/exercises/space-age/example.js