# Finders Keeper Algorithm help

**URL:** <https://forum.freecodecamp.org/t/finders-keeper-algorithm-help/60625>\
**Category:** General\
**Created:** [November 30, 2016, 11:18am UTC](https://forum.freecodecamp.org/t/finders-keeper-algorithm-help/60625 "2016-11-30T11:18:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tormundgiantsbane](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@tormundgiantsbane](https://forum.freecodecamp.org/u/tormundgiantsbane)\
**Post date:** [November 30, 2016, 11:18am UTC](https://forum.freecodecamp.org/t/finders-keeper-algorithm-help/60625/1 "2016-11-30T11:18:22Z")

</div>

Here is the code:

```
function findElement(arr, func) {
  var num = 0;

  
  num = arr.filter(func);
  num.splice(1);
  
  num = num.join(" ");
 
  return num;
} 

```

And well it returns the right number, but I am not passing the challenge.

For example: `findElement([1, 3, 5, 8, 9, 10], function(num) { return num % 2 === 0; });`

^^ That returns 8, which is what it is supposed to return. But I am not getting the green checkmark that says I passed that test.

---

<div class="post-metadata">

**Author:** ![BenGitter](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bengitter/32/12192_2.png) [@BenGitter](https://forum.freecodecamp.org/u/BenGitter)\
**Post date:** [November 30, 2016, 11:27am UTC](https://forum.freecodecamp.org/t/finders-keeper-algorithm-help/60625/2 "2016-11-30T11:27:38Z")

</div>

Not sure why it doesn’t work, but instead of `join` you can better use `num[0]` this will also automatically return undefined if there is no element (second test):

```auto
function findElement(arr, func) {
  var num = 0;
  
  num = arr.filter(func);
  num.splice(1);
  
  return num[0];
}

```

---

<div class="post-metadata">

**Author:** ![jenovs](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jenovs/32/60963_2.png) [@jenovs](https://forum.freecodecamp.org/u/jenovs)\
**Post date:** [November 30, 2016, 11:50am UTC](https://forum.freecodecamp.org/t/finders-keeper-algorithm-help/60625/3 "2016-11-30T11:50:25Z")

</div>

It doesn’t work because `.join()` returns string.

---

<div class="post-metadata">

**Author:** ![tormundgiantsbane](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@tormundgiantsbane](https://forum.freecodecamp.org/u/tormundgiantsbane)\
**Post date:** [November 30, 2016, 1:30pm UTC](https://forum.freecodecamp.org/t/finders-keeper-algorithm-help/60625/4 "2016-11-30T13:30:36Z")

</div>

Yeah that fixed it, thanks

---

<div class="post-metadata">

**Author:** ![jwilkins.oboe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jwilkins.oboe/32/179497_2.png) [@jwilkins.oboe](https://forum.freecodecamp.org/u/jwilkins.oboe)\
**Post date:** [January 16, 2021, 6:10am UTC](https://forum.freecodecamp.org/t/finders-keeper-algorithm-help/60625/5 "2021-01-16T06:10:05Z")

</div>

Closed on January 16, 2021, 6:10am UTC


