Created
October 17, 2014 18:02
-
-
Save kentcdodds/e890fdd9baea711bd49f to your computer and use it in GitHub Desktop.
starts and ends with mixins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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