1.0.0 • Published 2 years ago
@ryanthedev/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 @ryanthedev/lotide
Require it:
const _ = require('@ryanthedev/lotide');
Call it:
const results = _.tail([1, 2, 3]) // => [2, 3]
Documentation
The following functions are currently implemented:
assertArraysEqual(arr1, arr2)
: Outputs a console.log message stating ifarr1
andarr2
are equivalent arraysassertEqual(actual, expected)
: Outputs a console.log message stating ifactual
andexpected
are equalassertObjectsEqual(obj1, obj2)
: Outputs a console.log message stating ifobj1
andobj2
have the same key-value pairscountLetters.js(string)
: Returns an object with the keys being the letters that occur instring
and the values being the number of times the letter occurs instring
countOnly(arr, obj)
: Returns an object containing the counts of everything that obj listedeqArrays(arr1, arr2)
: Returns true ifarr1
andarr2
are equivalent, returns false if otherwiseeqObjects(obj1, obj2)
: Returns true ifobj1
andobj2
have the same key-value pairs, returns false if otherwisefindKey(obj, callback)
: Returns the first key inobj
for which thecallback
returns a truthy value, returns undefined if no key is foundfindKeyByValue(obj, value)
: Returns the key inobj
which has the the valuevalue
, returns undefined if no key existsflatten(arr)
: Returns a flattened version ofarr
given thatarr
has at most, one level of nestinghead(arr)
: Returns the first element inarr
. Ifarr
is empty, returns an empty arrayletterPosition(string)
: Returns an object where they keys are the letters that occur instring
and the values are all the indices where each letter is found.map(arr, callback)
: Returns a new array consisting of the values of returned bycallback
on each of the elements inarr
middle(arr)
: Returns an array consisting of the middle element(s) inarr
tail(arr)
: Returns an array consisting of the elements inarr
, excluding the first elementtakeUntil(arr, callback)
: Returns a slice ofarr
with elements being taken from the beginning until thecallback
returns a truthy valuewithout(source, itemsToRemove)
: Returns a new array with only those elements fromsource
that are not present initemsToRemove
1.0.0
2 years ago