1.0.0 • Published 3 years ago
@tangivan/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 @tangivan/lotide
Require it:
const _ = require('@tangivan/lotide');
Call it:
const results = _.tail([1, 2, 3]) // => [2, 3]
Documentation
The following functions are currently implemented:
tail(arr)
: Take in an array and return themiddle(arr)
: Take in an array and return the middle-most element(s) of the given array.flatten(arr)
: Take in an array containing elements including nested arrays of elements, and return a "flattened" version of the array.map(array, callback))
: Takes in anarray
andcallback
function. Returns a new array with the results of the callback function.takeUntil(array, callback)
: Takes in anarray
andcallback
function. Returns a slice of the array up to the first truthy value returned fromcallback
without(source, itemsToRemove)
: Takes in asource
array and anitemsToRemove
array. Returns an array without items fromitemsToRemove
and only the leftover items insource
.assertArraysEqual(actual, expected)
: Assertion function for arrays which takes in theactual
array and anexpected
array. Return assertion messages in the console on whether they passed or failed the test.assertEqual(expected, actual)
: Assertion function for primitive data types which takes in theactual
value and anexpected
value. Return assertion messages in the console on whether they passed or failed the test.assertObjectsEqual(actual, expected)
: Assertion function for objects which takes in theactual
object and anexpected
object. Return assertion messages in the console on whether they passed or failed the test.countLetters(string)
: Take in a string and return an object with the individual characters as the key and the count of said characters as the value.countOnly(allItems, itemsToCount)
: Take in an array of itemsallItems
and return a count ofitemsToCount
only.eqArrays(arr1, arr2)
: Take in 2 arrays and returntrue
if their contents are equal, orfalse
if their contents are not equal.eqObjects(obj1, obj2)
: Take in 2 objects and returntrue
if their contents are equal, orfalse
if their contents are not equal.findKey(obj, callback)
: Takes in an object and a callback. Returns the first key for which the callback returns a truthy value. If no key is found, then it should returnundefined
findKeyByValue(obj, val)
: Takes in an objectobj
and a valueval
and returns thekey
of the input object which holds the input value.letterPositions(string)
: take in a stringstring
which will return all the indices (zero-based positions) in thestring
where each character is found.
1.0.0
3 years ago