From 91887bc2d54de67cb8a0ed1f6e70ded4d56015ea Mon Sep 17 00:00:00 2001 From: Jeff Zhang <72734421+jeff-zhenz@users.noreply.github.com> Date: Thu, 12 May 2022 07:52:56 +0800 Subject: [PATCH] improvements: isSubsetOf function of Set --- src/js/data-structures/set.js | 14 ++------------ src/ts/data-structures/set.ts | 16 ++-------------- 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/src/js/data-structures/set.js b/src/js/data-structures/set.js index 0dc29a0c..996316ac 100644 --- a/src/js/data-structures/set.js +++ b/src/js/data-structures/set.js @@ -63,18 +63,8 @@ export default class Set { } isSubsetOf(otherSet) { - if (this.size() > otherSet.size()) { - return false; - } - let isSubset = true; - this.values().every(value => { - if (!otherSet.has(value)) { - isSubset = false; - return false; - } - return true; - }); - return isSubset; + const values = this.values(); + return values.every((value) => otherSet.has(value)); } isEmpty() { diff --git a/src/ts/data-structures/set.ts b/src/ts/data-structures/set.ts index c67faf75..a6d37373 100644 --- a/src/ts/data-structures/set.ts +++ b/src/ts/data-structures/set.ts @@ -75,20 +75,8 @@ export default class Set { } isSubsetOf(otherSet: Set) { - if (this.size() > otherSet.size()) { - return false; - } - - let isSubset = true; - this.values().every(value => { - if (!otherSet.has(value)) { - isSubset = false; - return false; - } - return true; - }); - - return isSubset; + const values = this.values(); + return values.every((value) => otherSet.has(value)); } isEmpty() {