api/notifications.js
function findPreviousAndNextTransactions(txns, callback) {

    // Find the index in the array of the baseTransaction
    var baseTransactionIndex = _.findIndex(txns, function(possibility) {
      if (possibility.hash === notificationDetails.transaction.hash) {
        return true;
      } else if (possibility.client_resource_id &&
        (possibility.client_resource_id ===
          notificationDetails.transaction.client_resource_id ||
        possibility.client_resource_id === notificationDetails.identifier)) {
        return true;
      }
      return false;
    });

    // The previous transaction is the one with an index in
    // the array of baseTransactionIndex - 1
    if (baseTransactionIndex > 0) {
      var previous_transaction = txns[baseTransactionIndex - 1];
      notificationDetails.previous_transaction_identifier =
        (previous_transaction.from_local_db ?
          previous_transaction.client_resource_id : previous_transaction.hash);
      notificationDetails.previous_hash = previous_transaction.hash;
    }

    // The next transaction is the one with an index in
    // the array of baseTransactionIndex + 1
    if (baseTransactionIndex + 1 < txns.length) {
      var next_transaction = txns[baseTransactionIndex + 1];
      notificationDetails.next_transaction_identifier =
        (next_transaction.from_local_db ?
            next_transaction.client_resource_id : next_transaction.hash);
      notificationDetails.next_hash = next_transaction.hash;
    }

    callback(null, notificationDetails);
  }
function findPreviousAndNextTransactions(txns, callback) {

    // Find the index in the array of the baseTransaction
    var baseTransactionIndex = _.findIndex(txns, function(possibility) {
      if (possibility.hash === notificationDetails.transaction.hash) {
        return true;
      } else if (possibility.client_resource_id &&
        (possibility.client_resource_id ===
          notificationDetails.transaction.client_resource_id ||
        possibility.client_resource_id === notificationDetails.identifier)) {
        return true;
      }
      return false;
    });

    // The previous transaction is the one with an index in
    // the array of baseTransactionIndex - 1
    if (baseTransactionIndex > 0) {
      var previous_transaction = txns[baseTransactionIndex - 1];
      notificationDetails.previous_transaction_identifier =
        (previous_transaction.from_local_db ?
          previous_transaction.client_resource_id : previous_transaction.hash);
      notificationDetails.previous_hash = previous_transaction.hash;
    }

    // The next transaction is the one with an index in
    // the array of baseTransactionIndex + 1
    if (baseTransactionIndex + 1 < txns.length) {
      var next_transaction = txns[baseTransactionIndex + 1];
      notificationDetails.next_transaction_identifier =
        (next_transaction.from_local_db ?
            next_transaction.client_resource_id : next_transaction.hash);
      notificationDetails.next_hash = next_transaction.hash;
    }

    callback(null, notificationDetails);
  }
function findPreviousAndNextTransactions ( txns , callback ) { // Find the index in the array of the baseTransaction var baseTransactionIndex = _ . findIndex ( txns , function ( possibility ) { if ( possibility . hash === notificationDetails . transaction . hash ) { return true ; } else if ( possibility . client_resource_id && ( possibility . client_resource_id === notificationDetails . transaction . client_resource_id || possibility . client_resource_id === notificationDetails . identifier ) ) { return true ; } return false ; } ) ; // The previous transaction is the one with an index in // the array of baseTransactionIndex - 1 if ( baseTransactionIndex > 0 ) { var previous_transaction = txns [ baseTransactionIndex - 1 ] ; notificationDetails . previous_transaction_identifier = ( previous_transaction . from_local_db ? previous_transaction . client_resource_id : previous_transaction . hash ) ; notificationDetails . previous_hash = previous_transaction . hash ; } // The next transaction is the one with an index in // the array of baseTransactionIndex + 1 if ( baseTransactionIndex + 1 < txns . length ) { var next_transaction = txns [ baseTransactionIndex + 1 ] ; notificationDetails . next_transaction_identifier = ( next_transaction . from_local_db ? next_transaction . client_resource_id : next_transaction . hash ) ; notificationDetails . next_hash = next_transaction . hash ; } callback ( null , notificationDetails ) ; }
Find the baseTransaction amongst the results. Because the transactions have been sorted, the next and previous transactions will be the ones on either side of the base transaction
Find the baseTransaction amongst the results . Because the transactions have been sorted the next and previous transactions will be the ones on either side of the base transaction