@kk2022/lotide
v1.0.0
Published
A clone of the lodash JavaScript library to practice creating various types of functions using JS
Downloads
12
Readme
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 @kk2022/lotide
Require it:
const _ = require('@kk2022/lotide');
Call it:
const results = _.tail([1, 2, 3]) // => [2, 3]
Documentation
The following functions are currently implemented:
assertArraysEqual(array1, array2)
: Asserts whether two arrays are identicalassertEqual(actual, expected)
: Asserts whether two primitive values are strictly equalassertObjectsEqual(object1, object2)
: Asserts whether two objects are identicalassertObjectsEqual(object1, object2)
: Asserts whether two objects are identicalcountLetters(sentence)
: Counts occurrences of characters in input string and returns object with character and count as key-value pairscountOnly(allItems, itemsToCount)
: Takes in an array of items and an object specifying subset of those items to be counted; outputs object with item and count as key-value pairseqArrays(array1, array2)
: Compares two arrays and returns true if they're identical, false otherwise (accepts nested arrays)eqObjects(object1, object2)
: Compares two objects and returns true if they're identical, false otherwise (accepts nested arrays & objects)findKey(object, callback)
: Scan's input object and returns first key whose value evaluates to true when passed into the callback function; returns undefined if none foundfindKeyByValue(object, searchValue)
: Scan's input object and returns first key whose value matches that of the second argument; returns undefined if none foundflatten(array)
: Takes in array with up to one additional layer of nested arrays and returns a non-nested (flat) array that contains all the values from the inputhead(array)
: Returns the first element of the input array, aka the "head" of the arrayletterPositions(sentence)
: Takes in a string and returns an object that contains: each character found in the input (as keys) and an array with the indices in which they were found (as values); skips white spacesmap(array, callback)
: Passes each element of the input array into the callback function and returns a new array with the returned valuesmiddle(array)
: Takes in an array and returns the one or two middle elements depending on whether input has odd or even number of elements; returns empty array if input has two or less elementstail(array)
: Takes in an array and returns all but the first element, aka the "tail" of the arraytakeUntil(array)
: Copies each element of the input array into a new array until an element evaluates to true when passed to the callback functionwithout(array)
: Takes in a source array and an array specifying items to be removed; returns the filtered array