Skip to content

Instantly share code, notes, and snippets.

@kentcdodds
Created October 17, 2014 18:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kentcdodds/e890fdd9baea711bd49f to your computer and use it in GitHub Desktop.
Save kentcdodds/e890fdd9baea711bd49f to your computer and use it in GitHub Desktop.
starts and ends with mixins
(function() {
'use strict';
_.mixin({
startsWith: function startsWithMixin(s1, s2) {
return startsOrEndsWith(_.first, s1, s2);
},
endsWith: function endsWithMixin(s1, s2) {
return startsOrEndsWith(_.last, s1, s2);
}
});
function startsOrEndsWith(fn, s1, s2) {
return s1 && s2 && s1.length > s2.length && fn(s1, s2.length).join('') === s2;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment