1.1.2 • Published 1 year ago
@mike.simnes/lotide v1.1.2
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 @mike.simnes/lotide
Require it:
const _ = require('@mike.simnes/lotide');
Call it:
const results = _.tail([1, 2, 3]) // => [2, 3]
Documentation
The following functions are currently implemented:
assertArraysEqual(arrayOne, arrayTwo)
: function to display the appropriate message to the console if two arrays match or not leveraging existing eqArrays function.assertEqual(actual, expected)
: logs a clear message to the console whether actual === expected or not.asserObjectsEqual(object1, object2)
: leverages eqObjects and eqArrays and returns a clear message to the console if they match or not.countLetters(string)
: takes in a string or several strings adn returns the count of letters excluding whitespaces.countOnly(allItems, itemsToCount)
: This function takes in a collection of allItems and return counts for items selected in itemsToCount.eqArrays(arrayOne, arrayTwo)
: Compares two arrays and returns true or false if they match or not.eqObjects(objectOne, objectTwo)
: Compares objects to see if they are equal, works with nested objects and arrays.findKey(object, callback)
: Takes in an object and a callback, returns the key according to the callback passed in.findKeyByValue(object, value)
: Finds the key of the corresponding value passed in as an argument.flatten(array)
: Function to take in an array or array of nested arrays and return a flattened array. using recursion to find the depth of the array and then flatmap to flatten the array to the given depth.head(array)
: Returns the first item of an array.letterPositions(string)
: Takes in a string and returns an object with the letters and positions of each letter.map(array, callback)
: Returns a new array based on the results of the callback function.middle(array)
: Returns middle element if array length is odd, returns middle two items if length is even.tail(array)
: Returns a new array containing only the tail of the original array.takeUntil(array, callback)
: Returns a slice of the array from the beginning until the callback returns a truthy value.without(source, itemsToRemove)'
: Returns a subset of the first argument 'source' array, removing unwanted elements from the second arg 'itemsToRmemove'.