From 39d15d6087724bcd0c8d87f48edfb945b96bc3d8 Mon Sep 17 00:00:00 2001 From: Jason Rudolph & Nathan Sobo Date: Wed, 31 Jul 2013 16:21:41 -0700 Subject: [PATCH] Add _.isSubset --- spec/stdlib/underscore-extensions-spec.coffee | 8 ++++++++ src/stdlib/underscore-extensions.coffee | 3 +++ 2 files changed, 11 insertions(+) diff --git a/spec/stdlib/underscore-extensions-spec.coffee b/spec/stdlib/underscore-extensions-spec.coffee index 7bf4bf90d..f75a720d8 100644 --- a/spec/stdlib/underscore-extensions-spec.coffee +++ b/spec/stdlib/underscore-extensions-spec.coffee @@ -107,3 +107,11 @@ describe "underscore extensions", -> object: first: 1 second: 2 + + describe "_.isSubset(potentialSubset, potentialSuperset)", -> + it "returns whether the first argument is a subset of the second", -> + expect(_.isSubset([1, 2], [1, 2])).toBeTruthy() + expect(_.isSubset([1, 2], [1, 2, 3])).toBeTruthy() + expect(_.isSubset([], [1])).toBeTruthy() + expect(_.isSubset([], [])).toBeTruthy() + expect(_.isSubset([1, 2], [2, 3])).toBeFalsy() diff --git a/src/stdlib/underscore-extensions.coffee b/src/stdlib/underscore-extensions.coffee index 7d203ce76..5ad04b67a 100644 --- a/src/stdlib/underscore-extensions.coffee +++ b/src/stdlib/underscore-extensions.coffee @@ -195,4 +195,7 @@ _.mixin newObject[key] = value if value? newObject + isSubset: (potentialSubset, potentialSuperset) -> + _.every potentialSubset, (element) -> _.include(potentialSuperset, element) + _.isEqual = require 'tantamount'