by ankjevel · 10y ago · 0 comments
{
const m = {}
m.__alpha__ = 10
m.__bravo__ = 20
m.__defineGetter__('__proto__', () => 30)
Reflect.ownKeys(m).forEach(key => console.log(key))
}
EDIT: I can't format ... function count_unique_strings(l)
{
var m = {};
l.forEach(function(s)
{
m[s] = true;
});
var count = 0;
for(var k in m) ++count;
return count;
}
To see why this function is incorrect, run it with the following input: console.log(count_unique_strings(["alpha", "bravo", "bravo", "charlie"]));
console.log(count_unique_strings(["alpha", "bravo", "bravo", "__proto__"]));The implementation is wrong: you're using Object when you want to use Map. Object is not suitable for this, and seems like you know it, and it's in language specs.