Skip to content

Commit

Permalink
[Clock]: Fix examplar (exercism#205)
Browse files Browse the repository at this point in the history
* Fix

* Fix casing
  • Loading branch information
meatball133 authored Jul 11, 2023
1 parent 7e350cd commit 223aa13
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
27 changes: 19 additions & 8 deletions exercises/practice/clock/.meta/example.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,40 @@ class Clock
@at: (hour, minute=0) =>
new Clock(hour, minute)

constructor: (@hour, @minute) ->
constructor: (hour, minute = 0) ->
@hour = hour
@minute = minute
@flattenMinutes()
@flattenHours()

toString:->
"#{clean(@hour)}:#{clean(@minute)}"

plus: (num) ->
@minute += num
while @minute > 59
@hour += Math.floor(@minute / 60)
@minute = @minute % 60
while @hour > 23
@hour = @hour % 24
@flattenMinutes()
@flattenHours()
this

minus: (num) ->
@minute -= num
@flattenMinutes()
@flattenHours()
this

flattenMinutes: ->
while @minute < 0
@minute = 60 + @minute
@hour -= 1
if @minute > 59
@hour += Math.floor(@minute / 60)
@minute = @minute % 60

flattenHours: ->
while @hour < 0
@hour = 24 + @hour
this
if @hour > 23
@hour = @hour % 24

equals: (otherClock) ->
this.toString() == otherClock.toString()
Expand All @@ -36,5 +48,4 @@ class Clock
else
str


module.exports = Clock
4 changes: 4 additions & 0 deletions exercises/practice/clock/clock.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Clock


module.exports = Clock

0 comments on commit 223aa13

Please sign in to comment.