Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 939523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:48:15+00:00 2026-05-15T21:48:15+00:00

I was working on some code earlier today, when I realized, Hey! This code

  • 0

I was working on some code earlier today, when I realized, “Hey! This code would be more concise and semantic if I abstracted the idea of a boolean not out of an anonymous function and into a prototype function…”

Consider a predicate generator:

function equalTo(n) {
    return function(x) {
        return n==x;
    };
}

So you can use it like so:

[1,2,3,4,1,2,3,4].filter(equalTo(2)) == [2,2]

Now, my idea is to make a predicate “inverser”:

Function.prototype.not = function() {
    //???
}

So that you can say:

[1,2,3,4,1,2,3,4].filter(equalTo(2).not) == [1,3,4,1,3,4]

My first stab at the implementation was probably very naive:

Function.prototype.not = function () {
    return ! this(arguments);
}

And probably why it didn’t work.

How would you implement this function, and why?

I’m just trying to wrap my head around functional ideas, and know JavaScript well enough to know it can be used to do this, but just not how.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:48:16+00:00Added an answer on May 15, 2026 at 9:48 pm

    Your implementation won’t work for several reasons:

    • You need to return a function, not a boolean.
    • You should pass the arguments as-is, not wrapped in an array.
    • You should preserve the context (this keyword) that the function would have been called in.

    I would implement it like this:

    Function.prototype.not = function (context) {
        var func = this;
        return function() { return !func.apply(context || this, arguments); };
    }
    
    • I return an anonymous function (function() { ... })
    • I call apply to call the original function in the current contexts with the actual arguments.
    • (EDIT) Free bonus: I added an optional context parameter which will override this for the callback.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 490k
  • Answers 490k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Yours is pretty short, but if you want to use… May 16, 2026 at 9:54 am
  • Editorial Team
    Editorial Team added an answer Finally got the tool I was looking for. http://forge.mysql.com/tools/tool.php?id=273 Since… May 16, 2026 at 9:54 am
  • Editorial Team
    Editorial Team added an answer Everything still must be HTTPS to be secure. Otherwise an… May 16, 2026 at 9:54 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Ok, I wrote this question up earlier today but I decided to delete it
I changed some code on an android application that was working perfectly fine at
I was working on an abstract class to save on some code for a
I had some sample code I was working on and broke the link to
I have written some code that makes use of an open source library to
I have a form, MainForm, which was working just fine and dandy until earlier
I'm working on key handling in Javascript. I have done some research and I'd
I'm working on a routine to strip block or line comments from some C#
I have been working on an iPhone App for a couple of weeks now
A new question has arisen in relation to an earlier question of mine .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.