Skip to main content
added 1 character in body
Source Link
AZTECCO
  • 10.9k
  • 1
  • 15
  • 58

Ruby, 99 89 102 bytes

->y,m{(1..4).find{|d|(A=Date.new y,m,-d).wday<5}
A.strftime"%A %d#{A.day>30?'st':'th'}"}
require'time'

Try it online!

Explanation

Anonymous function tacking year and month as numbers.

We find which of the last 4 days of month ( checking backwards using -d ) are wdays (week days 0-indexed) less than 5 saving each time date object in constant A for later use.

When it's found loop is stopped so A is the last weekday of the month.

Then we format the output, we can only have 31th31st or xxstXXth.

Ruby, 99 89 102 bytes

->y,m{(1..4).find{|d|(A=Date.new y,m,-d).wday<5}
A.strftime"%A %d#{A.day>30?'st':'th'}"}
require'time'

Try it online!

Explanation

Anonymous function tacking year and month as numbers.

We find which of the last 4 days of month ( checking backwards using -d ) are wdays (week days 0-indexed) less than 5 saving each time date object in constant A for later use.

When it's found loop is stopped so A is the last weekday of the month.

Then we format the output, we can only have 31th or xxst

Ruby, 99 89 102 bytes

->y,m{(1..4).find{|d|(A=Date.new y,m,-d).wday<5}
A.strftime"%A %d#{A.day>30?'st':'th'}"}
require'time'

Try it online!

Explanation

Anonymous function tacking year and month as numbers.

We find which of the last 4 days of month ( checking backwards using -d ) are wdays (week days 0-indexed) less than 5 saving each time date object in constant A for later use.

When it's found loop is stopped so A is the last weekday of the month.

Then we format the output, we can only have 31st or XXth.

added 54 characters in body
Source Link
AZTECCO
  • 10.9k
  • 1
  • 15
  • 58

Ruby, 99 89 117102 bytes

->y,m{(a=(Date1.new(y).4).Datefind{|d|(A=Date.new( y,m,-1)d).reject{|d|d.wday>4wday<5}[-1])
A.strftime"%A %d#{aA.day>30?'st':'th'}"}
require'time'

Try it online!

Fixed restricted output at huge cost.

Never thought Ruby had ranges also for dates!Try it online!

Explanation

Anonymous function tacking year and month as numbers.

We pass the [First dayfind which of year ..the last day4 days of month  ( checking backwards using -1d )] range and reject wdays are wdays (week days 0-indexed) greater then 4less than 5 saving each time date object in constant A for later use.

We returnWhen it's found loop is stopped so A is the last elementweekday of the month.

Then we format the output, we can only have 31th or xxst

Ruby, 99 89 117 bytes

->y,m{(a=(Date.new(y)..Date.new(y,m,-1)).reject{|d|d.wday>4}[-1]).strftime"%A %d#{a.day>30?'st':'th'}"}
require'time'

Try it online!

Fixed restricted output at huge cost.

Never thought Ruby had ranges also for dates!

Explanation

Anonymous function tacking year and month as numbers.

We pass the [First day of year .. last day of month(-1)] range and reject wdays(week days 0-indexed) greater then 4.

We return the last element.

Ruby, 99 89 102 bytes

->y,m{(1..4).find{|d|(A=Date.new y,m,-d).wday<5}
A.strftime"%A %d#{A.day>30?'st':'th'}"}
require'time'

Try it online!

Explanation

Anonymous function tacking year and month as numbers.

We find which of the last 4 days of month  ( checking backwards using -d ) are wdays (week days 0-indexed) less than 5 saving each time date object in constant A for later use.

When it's found loop is stopped so A is the last weekday of the month.

Then we format the output, we can only have 31th or xxst

deleted 27 characters in body
Source Link
AZTECCO
  • 10.9k
  • 1
  • 15
  • 58

Ruby, 99 89 131117 bytes

->y,m{(a=(Date.new(y)..Date.new(y,m,-1)).reject{|d|d.wday>4}[-1]).strftime"%A %-d#%d#{%w(th st nd rd)[aa.day%10]||'th'day>30?'st':'th'}"}
require'time'

Try it online!Try it online!

Fixed restricted output at huge cost.

Never thought Ruby had ranges also for dates!

Explanation

Anonymous function tacking year and month as numbers.

We pass the [First day of year .. last day of month(-1)] range and reject wdays(week days 0-indexed) greater then 4.

We return the last element.

Ruby, 99 89 131 bytes

->y,m{(a=(Date.new(y)..Date.new(y,m,-1)).reject{|d|d.wday>4}[-1]).strftime"%A %-d#{%w(th st nd rd)[a.day%10]||'th'}"}
require'time'

Try it online!

Fixed restricted output at huge cost.

Never thought Ruby had ranges also for dates!

Explanation

Anonymous function tacking year and month as numbers.

We pass the [First day of year .. last day of month(-1)] range and reject wdays(week days 0-indexed) greater then 4.

We return the last element.

Ruby, 99 89 117 bytes

->y,m{(a=(Date.new(y)..Date.new(y,m,-1)).reject{|d|d.wday>4}[-1]).strftime"%A %d#{a.day>30?'st':'th'}"}
require'time'

Try it online!

Fixed restricted output at huge cost.

Never thought Ruby had ranges also for dates!

Explanation

Anonymous function tacking year and month as numbers.

We pass the [First day of year .. last day of month(-1)] range and reject wdays(week days 0-indexed) greater then 4.

We return the last element.

deleted 10 characters in body
Source Link
AZTECCO
  • 10.9k
  • 1
  • 15
  • 58
Loading
deleted 27 characters in body
Source Link
AZTECCO
  • 10.9k
  • 1
  • 15
  • 58
Loading
added 186 characters in body
Source Link
AZTECCO
  • 10.9k
  • 1
  • 15
  • 58
Loading
Using | instead of ||
Source Link
AZTECCO
  • 10.9k
  • 1
  • 15
  • 58
Loading
added 36 characters in body
Source Link
AZTECCO
  • 10.9k
  • 1
  • 15
  • 58
Loading
Source Link
AZTECCO
  • 10.9k
  • 1
  • 15
  • 58
Loading