From 5e1497b81ea8b560289182cd3c1dac26c2ff5734 Mon Sep 17 00:00:00 2001 From: Evan Hahn Date: Thu, 9 Sep 2021 10:50:50 -0500 Subject: [PATCH] Prefer `Set.prototype.values()` over `.entries()` Each iteration value in [`Set.prototype.entries()`][0] is an array of two identical values: const mySet = new Set(['a' , 'b', 'c']); console.log([...mySet.entries()]); // => [ [ 'a', 'a' ], [ 'b', 'b' ], [ 'c', 'c' ] ] That's unnecessary for this library, which can just use [`Set.prototype.values()`][1]. const mySet = new Set(['a' , 'b', 'c']); console.log([...mySet.values()]); // => [ 'a', 'b', 'c' ] This simplifies the code a bit and should result in a small speed improvement. [0]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries [1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values --- src/index.jst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.jst b/src/index.jst index 5d4ee2f..4ad0840 100644 --- a/src/index.jst +++ b/src/index.jst @@ -33,8 +33,8 @@ module.exports = function equal(a, b) { if ((a instanceof Set) && (b instanceof Set)) { if (a.size !== b.size) return false; - for (i of a.entries()) - if (!b.has(i[0])) return false; + for (i of a.values()) + if (!b.has(i)) return false; return true; }