This code:
_(gameState.loot)
.pick((value, key) -> key isnt "pickUpAnimations")
.filter ((d) -> _.isArray (d))
.reduce ((sum, d) -> sum.concat (d))
Gives me this error:
TypeError: 'undefined' is not a function (evaluating '(function(d) {
While this code is working fine:
removedAnimations = _.pick(gameState.loot, (value, key) -> key isnt "pickUpAnimations")
removedAnimations = _.filter removedAnimations, ((d) -> _.isArray (d))
removedAnimations = _.reduce removedAnimations, ((sum, d) -> sum.concat (d))
removedAnimations
It seems to me that they should do the same. The scheme gameState.lootlooks like this:
loot: {
ttl: 6000
slowBlinkWhenTtlLessThanPercent: 60
fastBlinkWhenTtlLessThanPercent: 30
resurrections: []
gold: []
health: []
equipment: []
pickUpAnimations: []
}
By the way, this is javascript generated from the first example:
return _(gameState.loot).pick(function(value, key) {
return key !== "pickUpAnimations";
}).filter((function(d) {
return _.isArray(d);
}).reduce((function(sum, d) {
return sum.concat(d);
})));
I tried the @Blender suggestion:
_(gameState.loot)
.pick (value, key) -> key isnt "pickUpAnimations"
.filter (d) -> _.isArray (d)
.reduce (sum, d) -> sum.concat (d)
But this gave me this error:
>> TypeError: 'undefined' is not a function (evaluating '"pickUpAnimations".filter(function(d) {
This is what javascript looks like:
return _(gameState.loot).pick(function(value, key) {
return key !== "pickUpAnimations".filter(function(d) {
return _.isArray(d.reduce(function(sum, d) {
return sum.concat(d);
}));
});
});