Created
March 31, 2015 06:02
-
-
Save shanecp/497b59ec060c966e46a9 to your computer and use it in GitHub Desktop.
LoDash - extension for implode (similar to PHP function)
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
_.mixin({ | |
implode: function (glue, collection) { | |
glue = glue || ''; | |
if (!_.isArray(collection)) return false; | |
if (collection.length == 1) return collection[0]; | |
var returnString = ''; | |
for (var i = 0, len = collection.length; i < len; i++) { | |
if (i !== 0) returnString += glue; | |
returnString += collection[i]; | |
} | |
return returnString; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you very much for this snippet. Helped me big time!