documentcloud/underscore — pull request #668 by ianb (2012-07-11 04:30:03+00:00)
Title: Add _.startsWith and _.endsWith

This adds `_.startsWith` and `_.endsWith`. These work with both strings and arrays.

Both methods are proposed on strings in Harmony: http://wiki.ecmascript.org/doku.php?id=harmony:string_extras – extending them to also work on arrays seems natural.

This makes specific tests for arrays, because it only makes sense for ordered collections. `_.isArray` seems crude and maybe wrong (e.g., why shouldn't it work with childNodes or something array-like), but I'm not sure how better to detect indexable ordered collections.

Also if the types don't work out it returns false. Should it throw an error? And there's implicit string coercion, which maybe is okay or maybe not.