1.0.0 • Published 2 years ago
@sartoriali5t/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 @c5ho/lotide
Require it:
const _ = require('@c5ho/lotide');
Call it:
const results = _.tail([1, 2, 3]) // => [2, 3]
Documentation
The following functions are currently implemented:
head(arr)
: returns the 'head' (first element) of an arraytail(arr)
: returns the 'tail' (index 1 to last element) of an arraymiddle()
: returns (in an array) the middle value of an array if there are an odd number of elements, otherwise returs the middle two values of an array from an arry of even number elementsassertEqual(actual, expected)
: returns if an Assertion is passed or failed for primitive data typeseqArray(arr1, arr2)
: returns true if arr1 is deeply equivalent to arr2assertArraysEqual(actual, expected)
: Assertion for a deep comparison of two arrays, used witheqArray(arr1, arr2)
eqObjects(obj1, obj2)
: returns true if obj1 is deeply equivalent to obj2assertObjectsEqual(actual, expected)
: Assertion for a deep comparison of two objects, used witheqObjects(obj1, obj2)
countLetters(string)
: returns (in an object) the number of occurences of each letter in a given stringcountOnly(listArr, itemsToCountObj)
: returns an object of key:value pairs of item:occurences given a list of items in an array and an object with key:value pairs being itemToCount:boolean; count the item if truefindKey(obj, callback)
: takes in an object and a callback function and returns the first key for which the callback returns a truthy value; if no key is found, undefined is returnedfindKeyByValue(obj, valueToFind)
: takes in an object and value and returns the first key of the corresponding value; if no key exists for that given value, return undefinedletterPositions(string)
: given a string, return an object of showing each letter in the string and it's position(s) in the stringmap(arr, callback)
: given an array and a callback function, return a new array based on the results of the callback functiontakeUntil(arr, callback)
: given an array and a callback function, return a 'slice' of the array from the beginning until the callback provides a truthy valuewithout(sourceArr, subsetArr)
: given a source array and subset array, return a new array that only includes items from the source array that are not in the subset array
1.0.0
2 years ago