<commit_before>'use strict';

var ghGot = require('gh-got');

var get_followers = function (username, token, callback) {
    ghGot('users/' + username + '/followers', { token: token }, callback);
};

var getResults = function (res1, res2, cb) {
    if (res1.err) {
        cb(res1.err);
        return;
    }

    if (res2.err) {
        cb(res2.err);
        return;
    }

    var followers1 = res1.data.items.map(function (user) {
        return user.login;
    });

    var followers2 = res2.data.items.map(function (user) {
        return user.login;
    });

    return [followers1, followers2];
};

function intersect(a, b) {
    var t;
    if (b.length > a.length) t = b, b = a, a = t; // indexOf to loop over shorter
    return a.filter(function (e) {
        if (b.indexOf(e) !== -1) return true;
    });
}

module.exports = function (username1, username2, token, cb) {

    if (typeof username1 !== 'string' || typeof username2 !== 'string') {
        throw new Error('Type error: usernames must be of type `string`');
    }

    if (typeof token === 'function') {
        cb = token;
        token = null;
    }

    var result1, result2;

    get_followers(username1, token, function (err, data) {
        result1 = { err: err, data: data };

        get_followers(username2, token, function (err, data) {
            result2 = { err: err, data: data };

            var followers = intersect.apply(null, getResults(result1, result2, cb));
            cb(null, followers);
        });
    });
};<commit_msg>Fixes + added intersect<commit_after>'use strict';

var ghGot = require('gh-got');

var get_followers = function (username, token, callback) {
    ghGot('users/' + username + '/followers', { token: token }, callback);
};

var getResults = function (res1, res2, cb) {
    if (res1.err) {
        cb(res1.err);
        return;
    }

    if (res2.err) {
        cb(res2.err);
        return;
    }

    var followers1 = res1.data.map(function (user) {
        return user.login;
    });

    var followers2 = res2.data.map(function (user) {
        return user.login;
    });

    return [followers1, followers2];
};

var intersect = function (a, b) {
    var result = [];
    while( a.length > 0 && b.length > 0 ) {
        if      (a[0] < b[0] ){ a.shift(); }
        else if (a[0] > b[0] ){ b.shift(); }
        else {
            result.push(a.shift());
            b.shift();
        }
    }

    return result;
};

module.exports = function (username1, username2, limit, token, cb) {

    if (typeof username1 !== 'string' || typeof username2 !== 'string') {
        throw new Error('Type error: usernames must be of type `string`');
    }

    if (typeof token === 'function') {
        cb = token;
        token = null;
    }

    var result1, result2;

    get_followers(username1, token, function (err, data) {
        result1 = { err: err, data: data };

        get_followers(username2, token, function (err, data) {
            result2 = { err: err, data: data };

            var followers = intersect.apply(null, getResults(result1, result2, cb));
            cb(null, followers);
        });
    });
};

var ghCF = require('./');
ghCF('addyosmani', 'paulirish', function (err, data) {
    console.log(data);
});
{'fraction_non_alphanumeric': 0.15654853620955317, 'fraction_numerical': 0.01694915254237288, 'mean_word_length': 2.282103134479272, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '4563238', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1043, 'n_words': 281}