AngularJS filter to convert a time (hh:mm:ss) to seconds

TL;DR Split, reverse, cast, and the power of 'reduce'.

The following AngularJS filter converts something in the form of hh:mm:ss or mm:ss to seconds.

'use strict';

angular.module('myApp.filters.time', [])
  .filter('timeToSeconds', function () {
    return function (time) {
      return time.split(':')
        .reverse()
        .map(Number)
        .reduce(function (pUnit, cUnit, index) {
          return pUnit + cUnit * Math.pow(60, index);
        });
    };
  });
Written on June 17, 2014