ga-wdi-boston/ruby-vs-js-array-methods-study

Age calculated incorrectly

Closed this issue · 4 comments

gaand commented

in lib/person.js

See a solution in ga-wdi-boston/ruby-vs-js-array-methods#5

So to summarize, in lib/person.js :

 'use strict'

 const Person = function (h) {
   Object.keys(h).forEach(k => this[k] = h[k])
 }

 Person.prototype.age = function () {
   const dob = new Date(this.dob)
   const today = new Date()
-   let thisYear = today.getFullYear()
+   let thisYear = today.getUTCFullYear()
-   if (dob.getMonth() > today.getMonth() ||
+   if (dob.getUTCMonth() > today.getUTCMonth() ||
-     dob.getMonth() === today.getMonth() &&
+     dob.getUTCMonth() === today.getUTCMonth() &&
-     dob.getDate() >= today.getDate()) {
+     dob.getUTCDate() >= today.getUTCDate()) {
        thisYear -= 1
  }

  return thisYear - dob.getFullYear()
 }

 module.exports = Person
gaand commented

@jordanallain This is not the place for corrections to the code. A commit referencing this issue is.

just making sure I had all the correct changes.

gaand commented

Well, checking the answers and having it lint clean are good places to start.