text: import { NotImplementedError } from '../extensions/index.js';
  
  /**
   * Create transformed array based on the control sequences that original
   * array contains
   * 
   * @param {Array} arr initial array
   * @returns {Array} transformed array
   * 
   * @example
   * 
   * transform([1, 2, 3, '--double-next', 4, 5]) => [1, 2, 3, 4, 4, 5]
   * transform([1, 2, 3, '--discard-prev', 4, 5]) => [1, 2, 4, 5]
   * 
   */
  export default function transform( arr) {
    const control_seq = [`--discard-next`, `--double-prev`, `--double-next`, `--discard-prev`];
    if(Array.isArray(arr) == false){
      throw new Error("'arr' parameter must be an instance of the Array!");
    };
  
    return arr.reduce((previousValue, currentItem, index) => {
      if (control_seq.includes(currentItem)) {
        return previousValue;
      }
  
      if (arr[index - 1] == `--discard-next`) {
        return previousValue;
      }
  
      if (arr[index - 1] == `--double-next`) {
        previousValue.push(currentItem, currentItem);
      } else {
        previousValue.push(currentItem);
      }
  
      if (arr[index + 1] == `--discard-prev`) {
        previousValue.splice(previousValue.length - 1, 1)
      }
  
      if (arr[index + 1] == `--double-prev`) {
        previousValue.push(currentItem)
      }
      return previousValue;
    }, []);
  }
  