Add _.isSubset

This commit is contained in:
Jason Rudolph & Nathan Sobo
2013-07-31 16:21:41 -07:00
committed by Nathan Sobo
parent eaba8ef016
commit 39d15d6087
2 changed files with 11 additions and 0 deletions

View File

@@ -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()

View File

@@ -195,4 +195,7 @@ _.mixin
newObject[key] = value if value?
newObject
isSubset: (potentialSubset, potentialSuperset) ->
_.every potentialSubset, (element) -> _.include(potentialSuperset, element)
_.isEqual = require 'tantamount'