-
Notifications
You must be signed in to change notification settings - Fork 13
Add .firstItem for symmetry #27
Comments
Periodic reminder that |
I like this idea. I think it makes code more readable since you don't need to figure out if the I even think we should have |
This also reads more fluently with the common pattern of chaining array prototype methods together, compare function shortestWord(words) {
return words.filter(word => word.length > 0)
.sort((a, b) => a.length - b.length)
.firstItem()
} with function shortestWord(words) {
return words.filter(word => word.length > 0)
.sort((a, b) => a.length - b.length)
[0]
} the former is a lot more readable as the dangling |
I realize that this would be a trivial syntactic sugar for
array[0]
, but.lastItem
you will automatically start typing.firstItem
even if it doesn't exist..shift()
and.pop()
(as opposed to iteration by index), using.firstItem
and.lastItem
makes the code more readable.The text was updated successfully, but these errors were encountered: