Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loosely comparator with Set gives false result #93

Closed
LuKks opened this issue Jan 22, 2023 · 1 comment
Closed

Loosely comparator with Set gives false result #93

LuKks opened this issue Jan 22, 2023 · 1 comment

Comments

@LuKks
Copy link

LuKks commented Jan 22, 2023

Hello! This library looks like a great alternative for deep-equal but there are some cases where I can't make it work:

console.log(deepEql(
  new Set([null, '', 1, 5, 2, false]),
  new Set([undefined, 0, '5', true, '2', '-000']),
  { comparator: loosely }
))

function isPrimitive (value) {
  return value === null || typeof value !== 'object'
}

function loosely (a, b) {
  // console.log('loosely', [typeof a, typeof b], [a, b])
  if (!isPrimitive(a)) return null
  if (!isPrimitive(b)) return null
  const equal = a == b
  // console.log('loosely primitives', [a, b], 'equal?', equal)
  return equal
}

Currently I'm trying to test against several deep-equal tests to ensure that is mostly compatible to not break anything in the lib switching. Probably it's a good idea as you could find bugs this way

Btw I took the loosely comaprator from here: #47 (comment)

Thanks!

@LuKks
Copy link
Author

LuKks commented Apr 8, 2023

Solved with own library: https://github.com/holepunchto/same-object

@LuKks LuKks closed this as completed Apr 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant