#Underscore Recreation I thought it would be fun to rewrite some of the most popular functions from Underscore.
Misc
- _.identity - Returns whatever value is passed as the argument
Collections
- _.first - Returns an array of the first n elements of an array
- _.last - Returns an array of the last n elements of an array
- _.each - Calls the iterator for each element of a collection (array or object)
- _.indexOf - Returns the index at which the target can be found in the array
- _.filter - Return all elements of an array that pass a truth test
- _.reject - Return all elements of an array that do not pass a truth test
- _.uniq - Produce a duplicate-free version of the array
- _.map - Return the results of applying an iterator to each element
- _.pluck - Takes an array of objects and returns an array of the values of a certain property in it
- _.reduce - Reduces an array or object to a single value
- _.contains - Determine if the array of object contains a given value
- _.every - Determine whether all of the elements match a truth test
- _.some - Determine whether any of the elements pass a truth test
- _.shuffle - Randomizes the order of an array's contents
- _.zip - Zip together two or more arrays with elements of the same index going together
- _.flatten - Takes a multidimensional array and converts it to a one-dimensional array
- _.intersection - Takes an arbitrary number of arrays and produces an array that contains every item shared between all the passed-in arrays
- _.difference - Takes the difference between one array and a number of other arrays. Only the elements present in just the first array will remain
- _.invoke - Calls the method named by function or key on each value in the list
Objects
- _.extend - Extend a given object with all of the properties of the passed in object(s)
- _.defaults - Like _.extend, but does not overwrite a key that already exists in the object
- _.sortBy - Sort the object's values by a criterion produced by an iterator
Functions
- _.once - Return a function that can be called at most one time
- _.memoize - Memorize an expensive function's results by storing them
- _.delay - Delays a function for the given number of milliseconds, and then calls it with the arguments supplied
How To Run
- Clone the repo
- You can run any of the functions within lex/lib.js by prepending them with a double underscore namespace __.functionName
- There are also a few tests within test.js to ensure some of the functions actually work