Exercise · Classes and prototypes · lesson 10 of 12
Exercise: duration
Complete the class Duration, a span of time in seconds. constructor(seconds) stores the number of seconds, and the getter seconds returns it. The static method static fromMinutes(minutes) creates a new Duration object from minutes, and the static method static longest(durations) returns the longest Duration object in the array.
new Duration(90).seconds→90Duration.fromMinutes(2).seconds→120Duration.longest([new Duration(5), new Duration(30)]).seconds→30
Constraints: seconds and minutes are non-negative integers; both static methods are called through the class, and instances lack them; durations in the array differ, and an empty array gives null.
Do not add extra imports unless the task says so explicitly.
Subscribe to take the course
The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.