1.0.0 • Published 2 years ago
@dkisel/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 @dkisel/lotide
Require it:
const _ = require('@dkisel/lotide');
Call it:
const results = _.tail([1, 2, 3]) // => [2, 3]
Documentation
The following functions are currently implemented:
assertArraysEqual(actual, expected)
: Compares two 1-D arrays and prints a Pass or Fail message.assertEqual(actual, expected)
: Compares two primitive values and prints a Pass or Fail message.assertObjectsEqual(actual, expected)
: Compares two objects with properties that are primitives or arrays and prints a Pass or Fail message.countLetters(string)
: Returns an object where keys are all letters in the string and corresponding values are their frequency.countOnly(allItems, itemsToCount)
: Takes an array of strings to count, and an object with strings as keys and 'true' or 'false' to indicate whether a string should be counted. Returns an object with strings in the list which should be counted as keys and their frequency as values.eqArrays(array1, array2)
: Returns True if 1-D arrays are equal and False otherwise.eqObjects(object1, object2)
: Returns True if two objects with properties that are primitives or arrays are equal and False otherwise.findKey(obj, callback)
: Takes an object and a callback function that returns a boolean. Returns the first key for which the value satisfies the condition given by the callback function.findKeyByValue(obj, value)
: Takes an object and a primitive, returns the first key of the object whose value is equivalent to the primitive.flatten(inputArray)
: Takes an array with at most one layer of depth, returns a 1-D array.head(inputArray)
: Returns the first element of the array.letterPositions(string)
: Returns an object where keys are all letters in the string and corresponding values are arrays with a list of their positions in the input string.map(array, callback)
: Returns a new array of elements created by calling the input callback function on each element of the input array.middle(inputArray)
: Outputs an array of 0 to 2 elements: empty if the array's length is < 3, otherwise one middle element if the array's length is odd or both middle elements if the array's length is even.tail(inputArray)
: Returns everything but the first element of the arraytail(array, callback)
: Returns an array of the elements of the input array up to the first element (exclusive) which evaluates to 'true' when passed to the callback functionwithoutwithout(source, itemsToRemove)
: Returns an array of elements present in the source array but absent in the items to remove array
1.0.0
2 years ago