<commit_before>var globalStack;

function makeStack() {
    var stack = [];

    // in order to capture escape event first
    document.body.addEventListener('keydown', function(e) {

        var key = e.keyCode ? e.keyCode : e.which;
        // yup i hard coded 27 sorry suckas
        if (key === 27) {
            while (!!stack.length && !(stack.pop())(e)) {}
        }
    }, true);

    function addEscapeHandler(handler) {
        stack.push(handler);
        return function() {
            removeEscapeHandler(handler);
        };
    }

    function removeEscapeHandler(handler) {
        stack.remove(function(handlerInStack) {
            return handler === handlerInStack;
        });
    }
    return {
        add: addEscapeHandler
    }
}

module.exports = function(global) {
    if (!global) {
        return makeStack();
    }

    if (!globalStack) {
        globalStack = makeStack();
    }
    return globalStack;
};
<commit_msg>use splice instead of remove<commit_after>var globalStack;

function makeStack() {
    var stack = [];

    // in order to capture escape event first
    document.body.addEventListener('keydown', function(e) {

        var key = e.keyCode ? e.keyCode : e.which;
        // yup i hard coded 27 sorry suckas
        if (key === 27) {
            while (!!stack.length && !(stack.pop())(e)) {}
        }
    }, true);

    function addEscapeHandler(handler) {
        stack.push(handler);
        return function() {
            removeEscapeHandler(handler);
        };
    }

    function removeEscapeHandler(handler) {
        var index = stack.indexOf(handler);
        if (index !== -1) {
            stack.splice(index, 1);
        }
    }
    return {
        add: addEscapeHandler
    };
}

module.exports = function(global) {
    if (!global) {
        return makeStack();
    }

    if (!globalStack) {
        globalStack = makeStack();
    }
    return globalStack;
};

{'fraction_non_alphanumeric': 0.12817851582771148, 'fraction_numerical': 0.005189413596263622, 'mean_word_length': 2.0219435736677114, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1489800', 'n_tokens_mistral': 573, 'n_tokens_neox': 552, 'n_words': 130}