-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
36 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,44 @@ | ||
class CalendarArray { | ||
getCalendar(...dates) { | ||
if (this.#isValidDateArg(dates)) { | ||
console.log('is valid'); | ||
} | ||
} | ||
|
||
/* | ||
Validates getCalendar arguments. | ||
- sample correct arguments | ||
[[2020, 3], [2012], [2007]] | ||
*/ | ||
#isValidDateArg(dates) { | ||
if (dates.length > 0) { | ||
for (let date of dates) { | ||
|
||
if (!Array.isArray(date)) { | ||
throw new TypeError(`type: ${typeof date} <- the argument is of the wrong type, array expected`); | ||
|
||
} else if (date.length === 0) { | ||
throw new Error(`length: ${date.length} <- array is empty`); | ||
} else { | ||
|
||
for (let value of date) { | ||
if (typeof value !== 'number') { | ||
throw new TypeError(`type: ${typeof value} <- invalid date type in this array of dates, expected number`); | ||
} | ||
} | ||
} | ||
} | ||
} else { | ||
throw new Error('Empty args array, pass an array with a date'); | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
// export globals | ||
if (typeof module !== 'undefined') { | ||
module.exports = new CalendarArray(); | ||
} else { | ||
window.CalendarArray = new CalendarArray(); | ||
window.calendarArray = new CalendarArray(); | ||
} |