function insert(array, element) {
        array.push(element);
        return function () {
            var index = array.indexOf(element);
            if (index > -1) {
                array.splice(index, 1);
            }
        };
    }
Inserts an element into an array. Returns a function which, when
called, will remove that element from the array.