1.0.0 • Published 2 years ago

@mt91-dev/lotide v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

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 @mt91-dev/lotide

Require it:

const _ = require('@mt91-dev/lotide');

Call it:

const results = _.tail([1, 2, 3]) // => [2, 3]

Documentation

The following functions are currently implemented:

  • assertArraysEqual = (array1, array2): Returns a true or false based on two arrays passed as arguments to the function and console.logs a message to the user based on the functions return.

  • assertEqual = function (actual, expected): Returns a true or false based on two arguments and console.logs a message to the user based on the return.

  • assertObjectsEqual = (object1, object2): Checks to ensure two objects passed as arguments to the function are exactly equal.

  • countLetters = (string): Takes a string as a parameter and returns an object with keys as the lettter in the string and the keys value for the letters frequency in the string.

  • countOnly = (allItems, itemsToCount): Takes an array of items and returns an object with keys and values for items specified to be counted as the functions second argument.

  • eqArrays = (array1, array2): Checks to ensure two arrays passed as arguments to the function are exactly equal and returns true or false.

  • eqObjects = (object1, object2): Checks to ensure two objects passed as arguments to the function are exactly equal and returns true or false.

  • findKey = (object, callback): This function iterates through an entire object passed as an argument and uses a callback to determine if the key exists. If it exists, it returns the key when encountered, if the key doesnt exist, it returns undefined after iterating entire object.

  • findKeyByValue = (object, value): This function takes an object and a value inside the object to determine which key the value belongs to. If the key is not found, the function does not return anything.

  • flatten = (nestedArray): This function takes arrays or an array of nested arrays as an argument and returns a flattened array, which will not have any nested arrays in it.

  • head = (arr): Thhis function returns the head of an array that is passed as an argument.

  • letterPositions = function (sentence): This function takes a string phrase as an argument and returns an object with a key for each letter in the string and an array as the value, where each element in the array is the index of each occurrence of the letter in the string.

  • map = (array, callback): The map function generates a new copy of an array passed using a callback.

  • middle = (midArr): The middle function returns the middle of an array, with either even or oddly numbered elements.

  • tail = (arr): The tail function returns the tail of an array that is passed as an argument.

  • takeUntil = (array, callback): This function returns a new copy of the array passed until it reaches the value specified and stops.

  • without = (source, itemsToRemove): This function takes two arguments as arrays and returns a new array and removes elements in the second argument from the first argument.