{"size": 663, "ext": "js", "max_stars_repo_path": "src/simple-chain.js", "max_stars_repo_name": "duxa2089/basic-js", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/simple-chain.js", "max_issues_repo_name": "duxa2089/basic-js", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/simple-chain.js", "max_forks_repo_name": "duxa2089/basic-js", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 18.4166666667, "max_line_length": 76, "alphanum_fraction": 0.5822021116}
const CustomError = require("../extensions/custom-error");

const chainMaker = {
  result: [],

  getLength() {
    return this.result.length;
  },

  addLink(value) {
    this.result.push(`( ${value} )`);
    return this;
  },
  removeLink(index) {
    if (index < 1 || this.getLength() < index || !Number.isInteger(index)) {
      this.result = [];
      throw Error();
    }
    this.result.splice(index - 1, 1);
    return this;
  },

  reverseChain() {
    this.result.reverse();
    return this;
  },

  finishChain() {
    let tmp = this.result.join('~~');
    this.result.splice(0, this.result.length)
    return tmp;
  }
};

module.exports = chainMaker;
