I'm looking for a way to take the contents of the underscore chain and pass it into a function, in this case the chain parses out the timestamp from the file and sorts the array by timestamp, gets the latest one then I'd like to simply reassemble the path with path.format
. Is there a way to do this with underscore that I'm simply overlooking?
return _.chain(dirFiles)
.filter(function(dirFile){
return dirFile.match(file.name)
})
.map(function(dirFile){
dirFile = path.parse(dirFile)
dirFile.timestamp = dirFile.name.split("-")[file.timestampPosition]
return dirFile
})
.sortBy("timestamp")
.last()
.inject(path.format)
.value()
No, there is not. However, lodash does provide a
_.thru
method since v3:You surely can
_.mixin
it into underscore :-)