lib/utils.js
function sortPostsByPublishedDate (pPosts) {
    if (! (pPosts instanceof Array) ) {
        throw new MeowError ("pPosts is not an array");
    }

    pPosts.sort(function (pFirst, pSecond) {
        pFirst = pFirst || {};
        pSecond = pSecond || {};
        var pFirstPublishedDate  = pFirst['published-date'],
            pSecondPublishedDate = pSecond['published-date'];

        if (moment(pFirstPublishedDate).isAfter(pSecondPublishedDate)) {
            return -1;
        }
        else if (moment(pFirstPublishedDate).isBefore(pSecondPublishedDate)) {
            return 1;
        }
        else {
            return pFirst.title.localeCompare(pSecond.title);
        }
    });
    return pPosts;
}
function sortPostsByPublishedDate (pPosts) {
    if (! (pPosts instanceof Array) ) {
        throw new MeowError ("pPosts is not an array");
    }

    pPosts.sort(function (pFirst, pSecond) {
        pFirst = pFirst || {};
        pSecond = pSecond || {};
        var pFirstPublishedDate  = pFirst['published-date'],
            pSecondPublishedDate = pSecond['published-date'];

        if (moment(pFirstPublishedDate).isAfter(pSecondPublishedDate)) {
            return -1;
        }
        else if (moment(pFirstPublishedDate).isBefore(pSecondPublishedDate)) {
            return 1;
        }
        else {
            return pFirst.title.localeCompare(pSecond.title);
        }
    });
    return pPosts;
}
function sortPostsByPublishedDate ( pPosts ) { if ( ! ( pPosts instanceof Array ) ) { throw new MeowError ( "pPosts is not an array" ) ; } pPosts . sort ( function ( pFirst , pSecond ) { pFirst = pFirst || { } ; pSecond = pSecond || { } ; var pFirstPublishedDate = pFirst [ 'published-date' ] , pSecondPublishedDate = pSecond [ 'published-date' ] ; if ( moment ( pFirstPublishedDate ) . isAfter ( pSecondPublishedDate ) ) { return - 1 ; } else if ( moment ( pFirstPublishedDate ) . isBefore ( pSecondPublishedDate ) ) { return 1 ; } else { return pFirst . title . localeCompare ( pSecond . title ) ; } } ) ; return pPosts ; }
This function will order the posts array according to its published date in descending order
@param pPosts object containing cached posts data filed under some category
This function will order the posts array according to its published date in descending order