text: import { NotImplementedError } from "../extensions/index.js";
  
  /**
   * Implement chainMaker object according to task description
   *
   */
  export default {
    res: [],
  
    getLength() {
      return this.res.length;
    },
    addLink(value) {
      arguments.length < 1 ? this.res.push("( )") : this.res.push(value);
      return this;
    },
    removeLink(position) {
      if (
        position <= 0 ||
        typeof position !== "number" ||
        position > this.res.length
      ) {
        this.res = [];
        throw new Error("You can't remove incorrect link!");
      }
      this.res.splice(position - 1, 1);
      return this;
    },
  
    reverseChain() {
      this.res.reverse();
      return this;
    },
  
    finishChain() {
      let brows = this.res.map((x) => (x = `( ${x} )`));
      this.res = [];
      return brows.join("~~");
    },
  };
  