There are three more collection transformation functions that we will mention briefly here:
_.toArray(list)
creates a nativeArray
object from a collection._.shuffle(list)
creates an array of randomized collection items using the Fisher-Yates shuffle algorithm._.sample(list, [n])
also creates an array of randomized collection items with an optional limit of n array items. If n is not specific, it returns one random item from the collection.
The last collection specific function for this chapter is _.invoke(list, methodName, *arguments)
that will call method methodName
for each collection item and will optionally pass an arguments list to the invoked method.