← Back to challenges

Longest Streak

JavaScriptHarddatesobjectsloopsgames

Instructions

Create a function that takes an array of date objects and return the "longest streak" (i.e. number of consecutive days in a row).

Example

longestStreak([
  {
    "date": "2019-09-18"
  },
  {
    "date": "2019-09-19"
  },
  {
    "date": "2019-09-20"
  },
  {
    "date": "2019-09-26"
  },
  {
    "date": "2019-09-27"
  },
  {
    "date": "2019-09-30"
  }
]) ➞ 3

Notes

An empty array should return 0.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.