1.0.0 • Published 4 years ago
@js2oh/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.
Usage
Install it:
npm install @js2oh/lotide
Require it:
const _ = require('@js2oh/lotide');
Call it:
const results = _.tail([1, 2, 3]) // => [2, 3]
Documentation
The following functions are currently implemented:
head(arr)
: returns the reference to the first element of the given array as an argumenttail(arr)
: returns the array except the first element as a new arraymiddle(arr)
: returns the middle element(s) of the given array as a new arraycountLetters(str)
: returns the object which counts the number of each letter appear in the given string as value and letters as keymap(arr, callback)
: invokes the given callback function on each element of the given array, stores the returned values as the elements to the new array, and returns this new arraycountLetters(allItems, itemsToCount)
: returns the objects that counts the number of specific array elements (selected by the given list of items) appear in the given arrayfindKey(obj, callback)
: invokes the given callback function on each value of the given object, and if the function returns true, then returns the first key of such object valuefindKeyByValue(myObj, searchVal)
: returns the first key of the object which is equal to the given valueflatten(myObj, arr)
: flattens the given 2d array into a new 1d array and returns that arrayletterPositions(sentence)
: returns the object whose keys are the letters appear in the given sentence and whose values are the arrays of the letter positionstakeUntil(array, callback)
: invokes the given callback function on each element of the given array, and if the function returns true, then returns all the elements before the element that made the function returns truewithout(source, itemsToRemove)
: returns the array minus the given list of values to remove as a new arrayprintAssert(passed, actual, expected)
: given the condition and two values, if the condition is true, then prints that the assert test passed to the standard output; otherwise, prints that the assert test failed, but prints two given values regardless of the given conditioneqPrimitives(actual, expected)
: compare the two given primitive values strictly and returns the result as a boolean valueeqArrays(actual, expected)
: compare the two given arrays strictly and returns the result as a boolean valueeqObjects(actual, expected)
: compare the two given objects strictly and returns the result as a boolean valueassertArraysEqual(actual, expected)
: compare the two given primitive values strictly and outputs the assert result to the standard outputassertObjectEqual(actual, expected)
: compare the two given arrays strictly and outputs the assert result to the standard outputassertEqual(actual, expected)
: compare the two given objects strictly and outputs the assert result to the standard output
1.0.0
4 years ago