function validate(sequence, tree) {
    try {
      if (!_isArray(sequence)) {
        throw new JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY');
      }

      if (tree) {
        tree = JSON.parse(JSON.stringify(tree)); //clone tree so that we can safely try applying operations

        apply.call(this, tree, sequence, true);
      } else {
        for (var i = 0; i < sequence.length; i++) {
          this.validator(sequence[i], i);
        }
      }
    } catch (e) {
      if (e instanceof JsonPatchError) {
        return e;
      } else {
        throw e;
      }
    }
  }
Validates a sequence of operations. If `tree` parameter is provided, the sequence is additionally validated against the object tree.
If error is encountered, returns a JsonPatchError object
@param sequence
@param tree
@returns {JsonPatchError|undefined}