title: Array is being mutated when using slice()
body: <pre><code>Array.prototype.indicesOf = function (el) {
      let indices = [];
      for (var i = this.length - 1; i &gt;= 0; i--) {
          if (this[i] === el)
            indices.unshift(i);
      }
      return indices;
  }
  
  class CommentNester {
  
    constructor(comments) {
      this.comments = comments;
      this.nestedComments = this.nest();
    }
  
    getComments() {
      return this.comments;
    }
  
    getNestedComments() {
      return this.nestedComments;
    }
  
    nest() {
  
      const comments = this.comments.slice();
  
      (function appendChildren(parent_id = null) {
  
        const childIndices = comments.map(comment =&gt; comment.parent_id).indicesOf(parent_id);
  
        childIndices.forEach(index =&gt; {
          const child = comments[index];
  
          if (parent_id) {
            const parentIndex = comments.findIndex(comment =&gt; comment.id === parent_id);
            if (!comments[parentIndex].children) {
               comments[parentIndex].children = [];
            }
            comments[parentIndex].children.push(child);
          }
  
          appendChildren(child.id);
        });
  
      })();
  
      return comments.filter(comment =&gt; comment.parent_id === null);
    }
  
  }
  
  const comments = [{
    id: 1,
    text: "Top level",
    parent_id: null
  }, {
    id: 2,
    text: "Top level",
    parent_id: null
  }, {
    id: 3,
    text: "Reply level 1",
    parent_id: 1
  }, {
    id: 4,
    text: "Reply level 1",
    parent_id: 2
  }, {
    id: 5,
    text: "Reply level 2",
    parent_id: 3
  }];
  </code></pre>
  
  <p><code>getComments()</code> shows the original <code>comments</code> array is mutated (it has <code>children</code>), but I want it to stay original. I'm using <code>.slice()</code> to create a copy, but for some reason it still gets mutated. Any ideas why?</p>
  
  <p>Codepen here: <a href="http://codepen.io/anon/pen/QpMWNJ?editors=1010" rel="nofollow noreferrer">http://codepen.io/anon/pen/QpMWNJ?editors=1010</a></p>