Skip to content

refactoring _.some #2999

@nimbus4gh

Description

@nimbus4gh

Hi

As part of an assignment before a JS bootcamp, I had to re-write some of the Underscore functions - sometimes in a simplified version. I just had a look at the original implementation of _.some, and I thought I might suggest simply (your adaptation of) this instead:

_.some = function (collection, predicate, context) {
  return !_.every(collection, (e, index) => !predicate.call(context, e, index, collection));
};

It's based on

  • 'some = true' being equivalent to 'none = false', and
  • 'none w/ predicate A' being equivalent to 'every w/ predicate non-A'.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions