@ricardowgomes/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 @ricardowgomes/lotide
Require it:
const lotide = require('@ricardowgomes/lotide');
Call it:
const results = lotide.tail([1, 2, 3]) // => [2, 3]
Documentation
The following functions are currently implemented:
countLetters(str)
: Receives astring
as an argument and return anobject
with the letterkey and number of times counted as value, that can be easily accessed with dot notation.countOnly(arr)
: Receives an array ofstrings
and returns anobject
with thestring
key and the number of times counted as value, that can be easily accessed with dot notation.findKey(obj, callback)
: Receives anobject
and acallback-function
define a criteria to return the first key based on the value of theobject
.findKeyByValue(obj, str)
: Receives anobject
and astring
that returns the first key based on the value of the argumentstring
. If the value is not in the object, it returnsundefined
.flatten(arr)
: Receives anarray
and if thisarray
is nested (2D array), it returns a flattenarray
, in other words, an 1Darray
.head(arr)
: Receives anarray
and returns the head element of thatarray
.map(arr, callback)
: Receives anarray
and acallback-function
, thefunction
returns thearray
with each element transformed based onfunction
logic provided.middle(arr)
: Receives anarray
, if thearray.length
is even, it returns anarray
with the two middle elements, if is odd, it returns the single middle element.letterPositions(str)
: Receives astring
as an argument and return anobject
with each letter as key and the index of each letter as value, that can be easily accessed with dot notation. If there is more than one of the same letter, the value of that letter is anarray
with all indexes.takeUntil(arr, callback)
: Receives anarray
and acallback-function
, that returns thearray
with the elements until specific logic of thefunction
.tail(arr)
: Receives anarray
as argument and returns the tail element of thatarray
.
3 years ago