Problem · String
Is This Date a Weekend?
Learn this problemProblem statement
Given a valid calendar date date in exact YYYY-MM-DD form, return true if it falls on Saturday or Sunday. Return false if it falls on Monday through Friday.
Interpret the date with the proleptic Gregorian calendar. The result depends only on the calendar date, not on a time zone or locale.
Function
isWeekend(date: String) → booleanExamples
Example 1
date = "2024-06-15"return = trueJune 15, 2024 is a Saturday, so the result is true.
Example 2
date = "2024-06-17"return = falseJune 17, 2024 is a Monday, so the result is false.
Example 3
date = "2000-01-02"return = trueJanuary 2, 2000 is a Sunday, so the result is true.
Constraints
datehas exactly ten characters inYYYY-MM-DDform.- The year is between
0001and9999, inclusive. dateis valid under the proleptic Gregorian calendar.