text: const { NotImplementedError } = require('../extensions/index.js');
  
  /**
   * Implement chainMaker object according to task description
   * 
   */
  const chainMaker = {
    chain: [],
  
    getLength() {
      this.chain.length;
    },
  
    addLink(value) {
      this.chain.push(`( ${String(value)} )`);
  
      return this;
    },
  
    removeLink(position) {
      if (typeof (position) != 'number' ||
        !Number.isInteger(position) ||
        position <= 0 ||
        position > this.chain.length) {
        this.chain = [];
        throw new Error('You can\'t remove incorrect link!');
      } else {
        let tmp = [];
  
        for (let i = 0; i < this.chain.length; i += 1) {
          if (i + 1 != position) {
            tmp.push(this.chain[i]);
          }
        }
  
        this.chain = tmp;
  
        return this;
      }
    },
  
    reverseChain() {
      this.chain.reverse();
  
      return this;
    },
  
    finishChain() {
      let tmp = this.chain.join('~~');
      this.chain = [];
      return tmp;
    }
  };
  
  module.exports = {
    chainMaker
  };
  