-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.js
More file actions
38 lines (31 loc) · 1.41 KB
/
clock.js
File metadata and controls
38 lines (31 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const { setClock } = require('./helpers/clock');
class Clock {
constructor(hours, minutes) {
this.hours = hours; // getting hours that provided as arg
this.minutes = minutes; // getting minutes that provided as arg
}
toString() {
// calling a method that expects hours & minutes that provided and returns the proper clock result
return setClock({ hours: this.hours, minutes: this.minutes });
}
plus(minutes) {
// calculation of basic minutes that provided plus the additional one
const totalMinutes = this.minutes + minutes;
// calling a method that expects hours & minutes that provided and returns the proper clock result
return setClock({ hours: this.hours, minutes: totalMinutes });
}
minus(minutes) {
// calculation of basic minutes that provided minus the additional one
const totalMinutes = this.minutes - minutes;
// calling a method that expects hours & minutes that provided and returns the proper clock result
return setClock({ hours: this.hours, minutes: totalMinutes });
}
equals(_class) {
// represents the basic clock
const prevClock = setClock({ hours: this.hours, minutes: this.minutes });
// represents the additional clock that provided through the method
const newClock = setClock({ hours: _class.hours, minutes: _class.minutes });
return prevClock === newClock; // returns the equality as expected
}
}
module.exports = { Clock };