Closed felixsanz closed 9 months ago
That's a good idea.
I think there are many people who never consider operating directly on arguments
without turning it immediately into an array, simply because it's often tricky to do so. Hence anything that works with arguments
automatically starts with that Array.prototype.slice.call
incantation.
But as you demonstrate, it's not necessary. Your solution is cleaner and more elegant.
@felixsanz @CrossEye Even i found the slice bit weird (though obviously this solution is correct too). I implemented it with reduce.
function duckCount() {
return Array.prototype.reduce.call(arguments,function(count, curr){
return count + +(Object.prototype.hasOwnProperty.call(curr,'quack'))
},0)
}
The solution implementation says:
But this is also valid:
So... why using slice.call()? If you are already using .filter, why use another thing too? (which is also irrelevant)