1.0.0 • Published 3 years ago
@x_c_li/lotide v1.0.0
Lotide
A mini clone of the Lodash library.
Purpose
BEWARE: This library was published for learning purposes. It is not intended for use in production-grade software.
This project was created and published by me as part of my learnings at Lighthouse Labs.
Usage
Install it:
npm install @x_c_li/lotide
Require it:
const _ = require('@x_c_li/lotide');
Call it:
const results = _.tail([1, 2, 3]) // => [2, 3]
Documentation
The following functions are currently implemented:
without(sourceArray, itemsToRemove)
: returns new array without specified items (itemsToRemove)takeUntil(array, callback)
: keep collecting items from provided array until callback provided returns truthy valuetail(list)
: returns everything but the first item in a listhead(list)
: only returns the first thing in that listflatten(nestedArray)
: takes in an array with a nested array of elements and returns a flattened version of the arraymiddle(array)
: returns the middle value, but for even length array, returns two values for middlemap(array, callback)
: returns a new array based on the results of the callback functionletterPositions(sentence)
: return all the indices (zero-based positions) in the string where each character is found.findKeyByValue(objectName, val)
: scans object and return first key which contains given value, if no key w given value is found, return undefinedfindKey(thing, callback)
: get truthy if callback works, undefined if callback doesn't workeqObjects(object1, object2)
: returns whether the two objects are equaleqArrays(array1, array2)
: returns whether the two arrays are equalcountOnly(allItems, itemsToCount)
:take in collection of items (strings) and return counts for a specific subset of those items --won't count everything, will return an object with the statscountLetters(sentence)
: returns object with a count of how many times a letter appeared in a stringassertObjectsEqual()
: uses eqObjects to log whether two object key value pairs are equal or notassertEqual(actual, expected)
: console.logs whether two (non-array or object) values are equal or not. Useful for testing.assertArraysEqual(actual,expected)
: uses eqArrays to see if console.log whether two arrays are equal or not. Useful for testing.swapper(key1, object1, key2, object2)
: swaps object 1 key 1 into object 2 key 2, and puts object 2 key 2 into object 1 key 1
1.0.0
3 years ago