1.0.3 • Published 2 years ago
@albertho/lotide v1.0.3
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 @albertho/lotide
Require it:
const _ = require('@albertho/lotide');
Call it:
const results = _.tail([1, 2, 3]) // => [2, 3]
Documentation
The following functions are currently implemented:
countLetters(str)
: returns a new object of all letters of a string and the number of times it appears in the stringcountOnly(str, obj)
: returns a new object of only the letters of a string found in the second argument and the number of times it appears in the stringeqArrays(arr1, arr2)
: returns true if 2 arrays have the same values; else, returns falseeqObjects(obj1, obj2)
: returns true if 2 objects have the same values; else, returns falsefindKey(obj, callback)
: returns the first key found that passes a callback function (passed in as the second argument)findKeyByValue(object, value)
: returns the first key found that matches a given valueflatten(arr)
: returns a new array with all sub-array elements concatenated recursivelyhead(arr)
: returns the first element of an arrayletterPositions(str)
: returns a new object with a key for each unique letter of a string, each with its value as an array of the letter's index position(s)map(arr, callback)
: returns a new array of elements that pass the callback function (passed in as the second argument)middle(arr)
: returns the middle element of an odd-length array, or the middle two elements of an even-length arraytail(arr)
: returns a new array consisting of the the tail of the original arraytakeUntil(arr, callback)
: returns a new array of all of the elements of the original array up until a stopping condition, dictated by a callback function (passed in as the second argument)without(arr1, arr2)
: returns a new array of all of the elements in the first array not included in the second array
Some additional assertion functions:
assertArraysEqual(arr1, arr2)
: returns aconsole.log
message comparing two arraysassertEqual(val1, val2)
: returns aconsole.log
message comparing two valuesassertObjectsEqual(obj1, obj2)
: returns aconsole.log
message comparing two objects