function applyPatch(document, patch, validateOperation, mutateDocument, banPrototypeModifications) {
    if (mutateDocument === void 0) { mutateDocument = true; }
    if (banPrototypeModifications === void 0) { banPrototypeModifications = true; }
    if (validateOperation) {
        if (!Array.isArray(patch)) {
            throw new exports.JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY');
        }
    }
    if (!mutateDocument) {
        document = helpers_js_1._deepClone(document);
    }
    var results = new Array(patch.length);
    for (var i = 0, length_1 = patch.length; i < length_1; i++) {
        // we don't need to pass mutateDocument argument because if it was true, we already deep cloned the object, we'll just pass `true`
        results[i] = applyOperation(document, patch[i], validateOperation, true, banPrototypeModifications, i);
        document = results[i].newDocument; // in case root was replaced
    }
    results.newDocument = document;
    return results;
}
Apply a full JSON Patch array on a JSON document.
Returns the {newDocument, result} of the patch.
It modifies the `document` object and `patch` - it gets the values by reference.
If you would like to avoid touching your values, clone them:
`jsonpatch.applyPatch(document, jsonpatch._deepClone(patch))`.

@param document The document to patch
@param patch The patch to apply
@param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.
@param mutateDocument Whether to mutate the original document or clone it before applying
@param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.
@return An array of `{newDocument, result}` after the patch