How idiomatic is my code?
var Clock = function(hour, minute) {
this.hour = hour || 0;
this.minute = minute || 0;
this.plus = function(minutes) {
computed_minutes = this.minute + minutes
if (computed_minutes > 60) {
this.minute = computed_minutes % 60
this.hour += computed_minutes / 60
} else {
this.minute = computed_minutes
}
if (this.hour >= 24) {
this.hour = this.hour - 24
}
this.hour = Math.round(this.hour)
this.minute = Math.round(this.minute)
return this;
},
this.minus = function(minutes) {
computed_minutes = this.minute - minutes
if (computed_minutes < 0) {
this.minute = 60 + computed_minutes % 60
this.hour -= (1 + Math.abs(computed_minutes / 60))
} else {
this.minute = computed_minutes;
}
if (this.hour < 0) {
this.hour = 24 + this.hour
}
this.hour = Math.round(this.hour)
this.minute = Math.round(this.minute)
return this;
},
this.equals = function(other) {
return this.hour == other.hour && this.minute == other.minute;
}
}
Clock.at = function(hour, minute) {
c = new Clock(hour, minute);
return c;
}
Clock.prototype.toString = function() {
function format(n) {
return n >= 10 ? n : "0" + n;
}
return format(this.hour) + ":" + format(this.minute)
}
module.exports = Clock;