Arib Alam
Arib Alam
DIAdiscord.js - Imagine an app
Created by Arib Alam on 4/12/2024 in #djs-questions
Bug With difference() Method in Collections
Hi, if I am understanding the documentation correctly, there appears to be a bug with the difference() method of the collections class. The example given and the descriptions states that the method should return a new collection showing what is present in the first collection, but not the second. However when I try to run it, it first returns what doesn't exists in the first collection and then what does exists. Given Example
const col1 = new Collection([['a', 1], ['b', 2]]);
const col2 = new Collection([['a', 1], ['c', 3]]);
console.log(col1.difference(col2));
// => Collection { 'b' => 2 }
console.log(col2.difference(col1));
// => Collection { 'c' => 3 }
const col1 = new Collection([['a', 1], ['b', 2]]);
const col2 = new Collection([['a', 1], ['c', 3]]);
console.log(col1.difference(col2));
// => Collection { 'b' => 2 }
console.log(col2.difference(col1));
// => Collection { 'c' => 3 }
My Code
const { Collection } = require("discord.js");

const col1 = new Collection([
["a", 1],
["b", 2],
]);
const col2 = new Collection([
["a", 1],
["c", 3],
]);
console.log(col1.difference(col2));
// => Collection { 'c' => 3, 'b' => 2 }
console.log(col2.difference(col1));
// => Collection { 'b' => 2, 'c' => 3 }
const { Collection } = require("discord.js");

const col1 = new Collection([
["a", 1],
["b", 2],
]);
const col2 = new Collection([
["a", 1],
["c", 3],
]);
console.log(col1.difference(col2));
// => Collection { 'c' => 3, 'b' => 2 }
console.log(col2.difference(col1));
// => Collection { 'b' => 2, 'c' => 3 }
D.js Version: [email protected]
9 replies