anvaka/set-vs-object

Subtle bug

elclanrs opened this issue · 2 comments

This program has a subtle bug. Open issue if you found it and I'll give you credit.

Since object keys are strings, anything that's not a string will be stringified, which will make the following true:

1 === '1'
{} === {}
[] === []
//...

👍

But I would use == :) More scary thing regarding this is [[]] == ''.

Beside that, when you have undefined or null in array, function returns strings 'undefined' and 'null'.

Very nice catch!

However there is a way to break this program even when elements of the array are strings.

#2 - gives a good hint towards this direction, though suggested input in #2 does not break the code. Can you come up with the input which breaks it?