A mini clone of the Lodash library.
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.
Install it:
npm install @adamhirzalla/lotide
Require it:
const _ = require('@adamhirzalla/lotide');
Call it:
const results = _.middle([1, 2, 3]) // => [2]
The following functions are currently implemented:
assertEqual(actual, expected)
: logs assertion message - Pass/Fail (operator: ===)eqArrays(firstArray, secondArray)
: returns true if both arrays are equal, otherwise false (operator: ===)assertArraysEqual(firstArray, secondArray)
: logs assertion message - Pass/Fail (operator: ===)eqObjects(firstObject, secondObject)
: returns true if both objects are equal, otherwise false (operator: ===)assertObjectsEqual(firstObject, secondObject)
: logs assertion message - Pass/Fail (operator: ===)head(array)
: returns the head element of a given arraytail(array)
: returns the tail array of a given arraymiddle(array)
: returns an array of the middle element for a given array- If array length is less than or equal 2: returns an empty array
- If array length is odd and greater than 2: returns an array with the middle element
- If array length is even and greater than 2: returns an array with both middle elements
flatten(array)
: flattens a given array into a single arraymap(array, callback)
: calls a given callback function on every element of a given arraycountLetters(string)
: returns an object with each character from a given string as the key, and its number of occurances as the key-valuecountOnly(allItems, itemsToCount)
: given an object itemsToCount with keys of what to count and a value of true/false, returns an object with number of occurances of each key from a given array of allItemsfindKey(object, callback)
: returns the key-name of the first truthy return of the callback function on a given objectfindKeyByValue(object, value)
: returns the key-name of the first key-value matching the given valuetakeUntil(array, callback)
: returns an array with all elements of a given array until it reaches a truthy return value from the given callback functionwithout(allItems, elementsToRemove)
: removes all instances of elements from a given array elementsToRemove from a main given array allItemslettPositions(string)
: returns an object with keys of all characters and their indices as key-values from a given string