Jack Franklin | b5bbcc0 | 2020-02-11 10:14:11 | [diff] [blame^] | 1 | "use strict"; |
| 2 | |
| 3 | var forEach = require("@sinonjs/commons").prototypes.set.forEach; |
| 4 | |
| 5 | /** |
| 6 | * Returns `true` when `s1` is a subset of `s2`, `false` otherwise |
| 7 | * |
| 8 | * @private |
| 9 | * @param {Array|Set} s1 The target value |
| 10 | * @param {Array|Set} s2 The containing value |
| 11 | * @param {Function} compare A comparison function, should return `true` when |
| 12 | * values are considered equal |
| 13 | * @returns {boolean} Returns `true` when `s1` is a subset of `s2`, `false`` otherwise |
| 14 | */ |
| 15 | function isSubset(s1, s2, compare) { |
| 16 | var allContained = true; |
| 17 | forEach(s1, function(v1) { |
| 18 | var includes = false; |
| 19 | forEach(s2, function(v2) { |
| 20 | if (compare(v2, v1)) { |
| 21 | includes = true; |
| 22 | } |
| 23 | }); |
| 24 | allContained = allContained && includes; |
| 25 | }); |
| 26 | |
| 27 | return allContained; |
| 28 | } |
| 29 | |
| 30 | module.exports = isSubset; |