<commit_before>'use strict';

var qs = require('querystring'),
    request = require('request');

var DISTANCE_API_URL = 'https://maps.googleapis.com/maps/api/distancematrix/json?';

var GoogleDistance = function() {
  this.apiKey = '';
  this.businessClientKey = '';
  this.businessSignatureKey = '';
};

GoogleDistance.prototype.get = function(args, callback) {
  var self = this;
  var options = this.formatOptions(args);
  this.fetchData(options, function(err, data) {
    if (err) return callback(err);
    self.formatResults(data, options, function(err, results) {
      if (err) return callback(err);
      return callback(null, results);
    });
  });
};

GoogleDistance.prototype.formatOptions = function(args) {
  var pipeIt = function (array) {
    var string = '';
    for (var i = array.length - 1; i >= 0; i--) {
      string += array[i] + '|';
    };
    string = string.substring(0, string.length - 1);
    return string;
  };

  var options = {
    index: args.index || null,
    origins: args.origin,
    destinations: args.destination,
    mode: args.mode || 'driving',
    units: args.units || 'metric',
    language: args.language || 'en',
    avoid: args.avoid || null,
    sensor: args.sensor || false,
    key: this.apiKey
  };

  if (!args.origin && args.origins) options.origins = pipeIt(args.origins);
  if (!args.destination && args.destinations) options.destinations = pipeIt(args.destinations);

  if (this.businessClientKey && this.businessSignatureKey) {
    delete options.key;
    options.client = this.businessClientKey;
    options.signature = this.businessSignatureKey;
  }
  if (!options.origins) {
    throw new Error('Argument Error: Origin is invalid');
  }
  if (!options.destinations) {
    throw new Error('Argument Error: Destination is invalid');
  }
  return options;
};

GoogleDistance.prototype.formatResults = function(data, options, callback) {<commit_msg>Now using array.join instead of native function<commit_after>'use strict';

var qs = require('querystring'),
    request = require('request');

var DISTANCE_API_URL = 'https://maps.googleapis.com/maps/api/distancematrix/json?';

var GoogleDistance = function() {
  this.apiKey = '';
  this.businessClientKey = '';
  this.businessSignatureKey = '';
};

GoogleDistance.prototype.get = function(args, callback) {
  var self = this;
  var options = this.formatOptions(args);
  this.fetchData(options, function(err, data) {
    if (err) return callback(err);
    self.formatResults(data, options, function(err, results) {
      if (err) return callback(err);
      return callback(null, results);
    });
  });
};

GoogleDistance.prototype.formatOptions = function(args) {
  var options = {
    index: args.index || null,
    origins: args.origin,
    destinations: args.destination,
    mode: args.mode || 'driving',
    units: args.units || 'metric',
    language: args.language || 'en',
    avoid: args.avoid || null,
    sensor: args.sensor || false,
    key: this.apiKey
  };

  if (!args.origin && args.origins) options.origins = args.origins.join('|');
  if (!args.destination && args.destinations) options.destinations = args.destinations.join('|');

  if (this.businessClientKey && this.businessSignatureKey) {
    delete options.key;
    options.client = this.businessClientKey;
    options.signature = this.businessSignatureKey;
  }
  if (!options.origins) {
    throw new Error('Argument Error: Origin is invalid');
  }
  if (!options.destinations) {
    throw new Error('Argument Error: Destination is invalid');
  }
  return options;
};

GoogleDistance.prototype.formatResults = function(data, options, callback) {
{'fraction_non_alphanumeric': 0.1446280991735537, 'fraction_numerical': 0.0011019283746556473, 'mean_word_length': 3.809271523178808, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '28308', 'n_tokens_mistral': 1101, 'n_tokens_neox': 1085, 'n_words': 256}