Am i doing something wrong with filter or?

Tell us what’s happening:
is it a bug or a feature or am i the only one having this problem.

if i use arrow function in filter with curly bracket they dont work
but if i remove the curly bracket they work just fine

Intermediate Algorithm Scripting: Seek and Destroy(Works)

function destroyer(arr) {
var arg = […arguments].slice(1)

return arr.filter(x=>
!arg.includes(x)
)
}

Intermediate Algorithm Scripting: Seek and Destroy(Don’t)

function destroyer(arr) {
var arg = […arguments].slice(1)

return arr.filter(x=>{
!arg.includes(x)
})
}

Intermediate Algorithm Scripting: Diff Two Arrays(Works)

function diffArray(arr1, arr2) {
var newArr = []

return arr1.concat(arr2).filter(x =>!arr1.includes(x) || !arr2.includes(x))
}

Intermediate Algorithm Scripting: Diff Two Arrays(Works)

function diffArray(arr1, arr2) {
var newArr = []

return arr1.concat(arr2).filter(x =>{!arr1.includes(x) || !arr2.includes(x)})

}

Intermediate Algorithm Scripting: Diff Two Arrays(Using Map Works Fine)

function diffArray(arr1, arr2) {
var newArr = [];

arr1.map(x=>{
if(!arr2.includes(x)){
newArr.push(x)}
})
arr2.map(x=>{
if(!arr1.includes(x)){
newArr.push(x)}
})

return newArr;
}

**Link to the challenge:1**
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/seek-and-destroy
**Link to the challenge:2**
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays

its okay i find out why. i must use return.

@jasonkwm Awesome! :sunny:

In the future, can you wrap your code between ``` like this:

https:/uploads/default/original/2X/4/470db50cc014204906db4a54e53a7442df544643.gif

This will make your code easier to read on the forum.

1 Like