# Please check my code. I wrote everything correctly, my code doesn't work

**URL:** <https://forum.freecodecamp.org/t/please-check-my-code-i-wrote-everything-correctly-my-code-doesnt-work/299098>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [July 27, 2019, 9:58pm UTC](https://forum.freecodecamp.org/t/please-check-my-code-i-wrote-everything-correctly-my-code-doesnt-work/299098 "2019-07-27T21:58:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kenesrd](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kenesrd/32/101562_2.png) [@Kenesrd](https://forum.freecodecamp.org/u/Kenesrd)\
**Post date:** [July 27, 2019, 9:58pm UTC](https://forum.freecodecamp.org/t/please-check-my-code-i-wrote-everything-correctly-my-code-doesnt-work/299098/1 "2019-07-27T21:58:06Z")

</div>

**Tell us what’s happening:**

**Your code so far**

```js

function whatIsInAName(collection, source) {
let src = Object.keys(source)

 return collection.filter((el) => src.map((k) => el.hasOwnProperty(k) && el[k]=== source[k])).reduce((a, b) => a && b);
}

console.log(whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" }));

```

**Your browser information:**

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36`.

**Link to the challenge:**

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

---

<div class="post-metadata">

**Author:** ![JScars](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jscars/32/72367_2.png) [@JScars](https://forum.freecodecamp.org/u/JScars)\
**Post date:** [July 27, 2019, 10:10pm UTC](https://forum.freecodecamp.org/t/please-check-my-code-i-wrote-everything-correctly-my-code-doesnt-work/299098/2 "2019-07-27T22:10:42Z")

</div>

Your function only returns 1 element… You could try to be more clear writing your code; saving space is almost never useful… Your code must be readable when you are working with others.

---

<div class="post-metadata">

**Author:** ![simonebogni](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/simonebogni/32/266841_2.png) [@simonebogni](https://forum.freecodecamp.org/u/simonebogni)\
**Post date:** [July 27, 2019, 10:19pm UTC](https://forum.freecodecamp.org/t/please-check-my-code-i-wrote-everything-correctly-my-code-doesnt-work/299098/3 "2019-07-27T22:19:50Z")

</div>

Hi, the reduce method should be concatenated after the map function instead of the filter one.  
This is the working code:

```auto
let src = Object.keys(source);

 arr = collection.filter(
   (el) => {
     return src.map((k) => el.hasOwnProperty(k) && el[k] === source[k]).reduce((a, b) => a && b);
   });

```

---

<div class="post-metadata">

**Author:** ![Kenesrd](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kenesrd/32/101562_2.png) [@Kenesrd](https://forum.freecodecamp.org/u/Kenesrd)\
**Post date:** [July 29, 2019, 10:00pm UTC](https://forum.freecodecamp.org/t/please-check-my-code-i-wrote-everything-correctly-my-code-doesnt-work/299098/4 "2019-07-29T22:00:30Z")

</div>

Thank you very much…

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 25, 2021, 12:24pm UTC](https://forum.freecodecamp.org/t/please-check-my-code-i-wrote-everything-correctly-my-code-doesnt-work/299098/5 "2021-01-25T12:24:09Z")

</div>

Closed on January 25, 2021, 12:24pm UTC


