title: Javascript Array Bug - by changing one all other arrays get changed
body: <p>I was doing Codeforces problem when I encountered a bug I don't actually know how to fix:</p>
  
  <p>Problem: </p>
  
  <blockquote>
    <p>Vasya has invented a new hash function of an array. It is calculated as follows. While the array has at least two elements, the first two elements, call them 1 and 2, are deleted, and the new element 2−1 is inserted to the beginning of the array. When the array has only one element, this number is a value of Vasya's hash function of this array.</p>
    
    <p>Vasya has the array 1
    , 2,..., . He performs  operations of the following form: "increase all elements in the segment [,] by ". After each operation he wants to know the value of Vasya's hash function of this array.</p>
    
    <p>Input: The first line contains an integer (1≤≤500000) — the size of the array.
    The second line contains  integers  (−109≤≤109) — the elements of the array.
    The third line contains an integer  (1≤≤200000) — the number of operations.
    Each of the next  lines contains three integers , ,  (1≤≤≤, −109≤≤109) — the parameters of the -th operation.</p>
    
    <p>Output: Output  lines. In the -th line output one integer — the value of Vasya's hash function after the -th operation.</p>
  </blockquote>
  
  <p>When I change an array (both inside and outside the while loop) automatically all the other array get changed too.</p>
  
  <p>I  don't really know what to try and how to fix it.</p>
  
  <pre><code>function hash(n, inputArray, q, operations){
  
      let result = [];
  
      for (const operation of operations) {   
          let new_array = array_operation(inputArray, operation[0], operation[1], operation[2]);
  
          while (new_array.length &gt;= 2) {
              let new_value = new_array.shift() + new_array.shift();
              new_array.unshift(new_value);
          }
  
          result.push(new_array.shift());
      }
      return result;
  }
  
  function array_operation(array, start, end, value){
      for (const i in array) if (i &gt;= --start &amp;&amp; i &lt; end) array[i] += value;
      return array;
  }
  
  console.log(hash(7, [4, 2, -5, 10, 4, -2, 6], 2, [[2, 4, -8,], [5, 7, 2], [3, 3, -1], [3, 7, 3]])); 
  </code></pre>