montagejs / collections

This package contains JavaScript implementations of common data structures with idiomatic interfaces.
http://www.collectionsjs.com
Other
2.1k stars 184 forks source link

Set behavior vary from Browser vs Node? #249

Open JSeligstein opened 1 year ago

JSeligstein commented 1 year ago

The following code appears to work as expected (true) in browser, but fails in a brand-new clean node project. Am I missing something?

const Set = require('collections/set'); const myset = new Set(null, function(a, b) {
return a.x == b.x && a.y == b.y;
}, function(object) {
return ''+object.x+'.'+object.y;
});

myset.add({x:0, y:0});
console.log(myset.has({x: 0, y:0}));

hthetiot commented 1 year ago

Please provide nodejs version.

JSeligstein commented 1 year ago

I literally ran:

node init node install --save collections

Then ran the above file.

hthetiot commented 1 year ago

@JSeligstein that not what I asked you. Please provide NodeJs and Npm version aka node --version and npm --version commands results...

hthetiot commented 1 year ago

Also this code does not pass the Javacript parser in my brain...

return ''+object.x+'.'+object.y;

See "+

Meaning even if I wanted your code is not valid anyway. You need provide valid code if you wish help, and name issue properly would be appreciated.

JSeligstein commented 1 year ago

For some reason, in the past I feel like if you did int + string + int it would try to cast everything to Number instead of strings. The old-school trick was to use a string first. '' + x + '.' + y is perfectly valid, though perhaps unnecessary it may seem. Feel free to remove the single-quotes there.

% node --version v19.0.1 % npm --version 8.19.2

I'm sorry about the original answer. I thought you meant version of code. I'm tired today.

hthetiot commented 1 year ago

Thank you, the nodejs version is usefull. I may assist with some issue here as co-maintainer.

No promise but I will look into giving some love to this project this weekend.