# Seek and Destroy: Why doesn't pop() work?

**URL:** <https://forum.freecodecamp.org/t/seek-and-destroy-why-doesnt-pop-work/485653>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [November 16, 2021, 10:30pm UTC](https://forum.freecodecamp.org/t/seek-and-destroy-why-doesnt-pop-work/485653 "2021-11-16T22:30:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sh0es](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sh0es/32/226101_2.png) [@Sh0es](https://forum.freecodecamp.org/u/Sh0es)\
**Post date:** [November 16, 2021, 10:30pm UTC](https://forum.freecodecamp.org/t/seek-and-destroy-why-doesnt-pop-work/485653/1 "2021-11-16T22:30:55Z")

</div>

**Tell us what’s happening:**  
I was able to come up with this solution to the “Seek and Destroy” exercise with this recursive function:

```js
function destroyer(arr, ...args) {
  if(args.length < 1)
  {
    return arr;
  }
  else if(args.length == 1)
  {
    return arr.filter(item => item != args[0]);
  }
  else
  {
    return destroyer(arr.filter(item => item != args[0]), ...args.slice(1));
  }
}

```

My question is this: originally, I was using `item != args.pop()` instead of `item != args[0]` and passing `args` in the final case without slicing. That cleared _every_ element from the array on the second recursion, contradicting my initial assumption that the interpreter was calling `pop()` twice in my code. Can anyone explain why `pop()` did this?

```
  **Your browser information:**

```

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0`

**Challenge:** Seek and Destroy

**Link to the challenge:**

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/seek-and-destroy)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![ArielLeslie](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/arielleslie/32/264841_2.png) [@ArielLeslie](https://forum.freecodecamp.org/u/ArielLeslie)\
**Post date:** [November 16, 2021, 10:57pm UTC](https://forum.freecodecamp.org/t/seek-and-destroy-why-doesnt-pop-work/485653/2 "2021-11-16T22:57:33Z")

</div>

`.pop()` mutates the array.

> **[Array.prototype.pop() - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)**
>
> The pop() method removes the last
> element from an array and returns that element. This method changes the length of the
> array.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [May 18, 2022, 10:58am UTC](https://forum.freecodecamp.org/t/seek-and-destroy-why-doesnt-pop-work/485653/3 "2022-05-18T10:58:29Z")

</div>

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
