Why will ES6 WeakMap’s not be enumerable?

Finally found the real answer: http://tc39wiki.calculist.org/es6/weak-map/ A key property of Weak Maps is the inability to enumerate their keys. This is necessary to prevent attackers observing the internal behavior of other systems in the environment which share weakly-mapped objects. Should the number or names of items in the collection be discoverable from the API, even … Read more

IEnumerable doesn’t have a Count method

You add: using System.Linq; at the top of your source and make sure you’ve got a reference to the System.Core assembly. Count() is an extension method provided by the System.Linq.Enumerable static class for LINQ to Objects, and System.Linq.Queryable for LINQ to SQL and other out-of-process providers. EDIT: In fact, using Count() here is relatively inefficient … Read more

Group hashes by keys and sum the values

ar = [{“Vegetable”=>10}, {“Vegetable”=>5}, {“Dry Goods”=>3}, {“Dry Goods”=>2}] p ar.inject{|memo, el| memo.merge( el ){|k, old_v, new_v| old_v + new_v}} #=> {“Vegetable”=>15, “Dry Goods”=>5} Hash.merge with a block runs the block when it finds a duplicate; inject without a initial memo treats the first element of the array as memo, which is fine here.

What does enumerable mean?

An enumerable property is one that can be included in and visited during for..in loops (or a similar iteration of properties, like Object.keys()). If a property isn’t identified as enumerable, the loop will ignore that it’s within the object. var obj = { key: ‘val’ }; console.log(‘toString’ in obj); // true console.log(typeof obj.toString); // “function” … Read more

Array#each vs. Array#map

Array#each executes the given block for each element of the array, then returns the array itself. Array#map also executes the given block for each element of the array, but returns a new array whose values are the return values of each iteration of the block. Example: assume you have an array defined thusly: arr = … Read more