-
-
Save thedelk/e6a61bb3dcfd2924711e925b1bc65a43 to your computer and use it in GitHub Desktop.
lodash utility methods
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({ | |
findByValues: function (collection, property, values) { | |
return _.filter(collection, function (item) { | |
return _.contains(values, item[property]); | |
}); | |
}, | |
sformat: function (format) { | |
var args = Array.prototype.slice.call(arguments, 1); | |
return format.replace(/{(\d+)}/g, function (match, number) { | |
return typeof args[number] != "undefined" ? args[number] : match; | |
}); | |
}, | |
}); |
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
const collections = [ | |
{ id: 1, name: "xyz" }, | |
{ id: 2, name: "ds" }, | |
{ id: 3, name: "rtrt" }, | |
{ id: 4, name: "nhf" }, | |
{ id: 5, name: "qwe" }, | |
]; | |
const filtered = _.findByValues(collections, "id", [1, 3, 4]); | |
_.sformat('I"m learning {0} but working in {1} {0}', "ng", "React"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment