function applyReducer(document, operation, index) {
    var operationResult = applyOperation(document, operation);
    if (operationResult.test === false) { // failed test
        throw new exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
    }
    return operationResult.newDocument;
}
Apply a single JSON Patch Operation on a JSON document.
Returns the updated document.
Suitable as a reducer.

@param document The document to patch
@param operation The operation to apply
@return The updated document