Skip to the content

The song in seconds

Problem

A song's length comes written as text, always with two digits on each side of the colon: "04:05" is four minutes and five seconds.

Write a function that takes that text and returns how many seconds it lasts in total, as a number: "04:05" gives 245 and "00:45" gives 45.

Examples

  • "04:05" → 245

  • "00:45" → 45

  • Whole minutes

    "12:00" → 720

Besides these, the challenge has hidden tests that are revealed when you submit your solution.

You start with this

Python

def to_seconds(text):
    pass

JavaScript

function toSeconds(text) {
}
Solve this challenge

It opens in your browser, with the editor and the tests. It is free and you do not need an account to start.

More O(1) challenges

See all challenges →