AniUI Academy
easy+150 XPPractice

Negate a predicate

You have a predicate and you need its opposite. Writing items.filter((x) => !isArchived(x)) works, but once you are composing filters you want the negated predicate as a value you can pass around and name.

Implement negate(predicate). It returns a new function that forwards every argument, and its this, to predicate, and returns the boolean opposite of the result. The return value is always a real boolean: a truthy result such as the string "hello" becomes false, and a falsy result such as 0 becomes true.

What it has to do

  • Return true when the predicate returns a falsy value, and false when it returns a truthy one.
  • Always return an actual boolean, never the negated operand itself.
  • Forward every argument the wrapper receives to the predicate.
  • Preserve this so a negated predicate works as an object method.

Your workspace

Try it yourself
Loading playground...

Ready to check it?

5 tests run against your code, right here in your browser. Sign in to claim the XP when you pass.

AI Crack & Solution Assist

Stuck? Get instant AI hints or break down the optimal solution.

Stuck? The javascript course covers everything this challenge needs.