Re:KindScript – A kinder JavaScript experience
by ankjevel on Sunday March 20, 2016 @11:10AM
(#11323211)
Why would you like to add anything to the __proto__ property? One way would be to write, like this:
EDIT: I can't format ...
[ Parent
| on HN ]
Re:KindScript – A kinder JavaScript experience
by amelius on Sunday March 20, 2016 @11:22AM
(#11323255)
To make my point clear, here is a question. What is wrong with the following function that counts the number of unique strings in a list of strings?
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__"]));
Re:KindScript – A kinder JavaScript experience
by dchest on Sunday March 20, 2016 @12:12PM
(#11323425)
What is wrong with the following function
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.