1.0.0 • Published 2 years ago
@trachea/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 @trachea/lotide
Require it:
const _ = require('@trachea/lotide');
Call it:
const results = _.tail([1, 2, 3]) // => [2, 3]
Documentation
The following functions are currently implemented:
assertArraysEqual(arr1, arr2)
: Used for internal testing. Checks ifarr1
andarr2
have the same elementsassertEqual(a, b)
: Used for internal testing. Checks ifa === b
. Only works for primitive data types.assertObjectsEqual(obj1, obj2)
: Used for internal testing. Checks if the two objects:obj1
andobj2
have the same keys-value pairs.countLetters(string)
: Takes in astring
and returns an object where the keys each unique letter instring
and the values are the number of occurences instring
.countOnly(arr, obj)
: Returns an objects where the keys are elements inarr
such that the key exists inobj
and it's value istrue
and the values are the number of occurences inarr
.eqArrays(arr1, arr2)
: Returns true only if all the elements inarr1
exist inarr2
and the lenght ofarr
andarr2
are the same.eqObjects(obj1, obj2)
: Returns true only if both objects have the same number of key-value pairs and every key-value pair inobj1
exists inobj2
.findKey(obj, function)
: Returns the first occurence of the key inobj
that satisfiesfunction
.function
must be a callback function that returns true only if a condition is met. If no key is found, returnsundefined
.findKeyByValue(obj, value)
: Returns the first occurence of the key inobj
that has valuevalue
. If no key is found, returnsundefined
.flatten(arr)
: Returns a new array that is contains every element inarr
flattened.head(arr)
: Returns the first element ofarr
.letterPositions(string)
: Returns an object that contains each unique letter instring
where the value is an array where the element representing the index where the key appears instring
.map(arr, function)
: Returns a new array that is the same length asarr
and each element is the result offunction(element)
.middle(arr)
: Returns an array that contains the middle value ofarr
. One value if length ofarr
is odd and two values if length ofarr
is even. If the length ofarr
is less or equal to two, then returns an empty array.tail(arr)
: Returns a new array which isarr
without it's first element.takeUntil(arr, function)
: Returns an array that is all the elements inarr
until an element satisifiesfunction
andfunction
returns true;without(sources, values)
: Returns an array that issources
where all occurences of any element invalues
has been removed.
1.0.0
2 years ago