text: const { NotImplementedError } = require('../extensions/index.js');
  
  /**
   * Implement chainMaker object according to task description
   * 
   */
   const chainMaker = {
      chain: '',
      getLength() {
          return this.chain.split('~~').length;
      },
      addLink(value = '') {
          (this.chain.length > 0) ? this.chain += `~~( ${value} )` : this.chain += `( ${value} )`;
          return this;
      },
      removeLink(position) {
          let lengthArr = this.chain.split('~~').length;
          if(position >0 && position < lengthArr && Number.isInteger(position)) {
              let chain = this.chain.split('~~');
              chain.splice(position - 1, 1);
              this.chain = chain.join('~~');
          } else {
              this.chain = '';
              throw new Error('You can\'t remove incorrect link!');
          }
          return this;
      },
      reverseChain() {
          this.chain = this.chain.split('~~').reverse().join('~~');
          return this;
      },
      finishChain() {
          let resultChain = this.chain;
          this.chain = '';
  
          return resultChain;
      }
  }
  
  module.exports = {
    chainMaker
  };
  