4 ms·
>> _.first(array) >> "Convenience to return the first element of an array (identical to array[0])." How is _.first(array) more convenient than array[0] ? :/
by axod 17y ago
>> _.first(array)
>> "Convenience to return the first element of an array (identical to array[0])."
How is _.first(array) more convenient than array[0] ? :/
- natrius 17y agoSometimes you need a function. The alternative isn't array[0]; it's function (array) { return array[0]; }.
- axod 17y agoAh thanks. Makes sense now.
- jashkenas 17y agoYep -- that one is questionable. It's there to provide symmetry with "_.last", which is definitely more convenient than: array[array.length - 1];
- jriddycuz 17y agoIt's more convenient to think about if your mind is in functional programming mode. Thought convenience is real convenience.
- osteele 17y agoWhen used in a functional context, these come to: >> _.map(listOfLists, _.first) vs. >> _.map(listOfLists, function(array) { return array[0]; }) for example.