Is it efficient?!

Hi, guys!

I was doing this challenge and after a while i’ve got this code. I’m proud with it, it looks tight and i used what i knew.

Do you find it efficient? And what can i do to make it more tight and clean?

Your code so far


function truthCheck(collection, pre) {

return collection

.map(x => x[pre])
.map(Boolean)
.every((x) => Boolean(x) === true);

}

console.log(truthCheck([{"name": "Pete", "onBoat": true}, {"name": "Repeat", "onBoat": true, "alias": "Repete"}, {"name": "FastForward", "onBoat": null}], "onBoat"));

Your browser information:

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

Challenge: Everything Be True

Link to the challenge:

There are a few things you can drop if you want.

  1. Boolean(x) === true is the same thing as Boolean(x)

  2. I think (someone else can probably chime in) that you might not need the .map(Boolean) part.

Overall, the solution works, which is #1 the most important part : ) Nice work!

1 Like

You definitely don’t need the second map. You don’t need the first one either.

spoiler
return collection.every(x => x[pre]);
1 Like