1.0.0 • Published 2 years ago

@hanson85711/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 @hanson85711/lotide

Require it:

const _ = require('@hanson85711/lotide');

Call it:

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

Documentation

The following functions are currently implemented:

  • assertArraysEqual(array, expectedArray): compares two arrays and prints out a message if they're equal
  • assertEqual(value, expectedValue): compares two values and prints out a message if theyre equal
  • assertObjectsEqual(object, expectedObject)): compares two objects and prints out a message if they're equal
  • countLetters(sentence): Takes in a string and counts how many letters are in the string. Omits spaces.
  • countOnly(allItems, itemsToCount): Take in a collection of items and counts how many strings are in the collection
  • eqArrays(array1, array2)): Takes in two arrays and returns true or falsed based on whether they match
  • eqObjects(object1, object2): Takes in two objects and returns true if both objects have identical keys with identical values. False otherwise.
  • findKey(object, callback): Takes in an object and a callback function and returns the key whose value matches the callback condition. Returns undefined if no key is found.
  • findKeyByValue(object, value): Takes in an object and a value and returns the first key that contains the given value. If no key with the given value is found, then it returns undefined.
  • head(array): Takes in an array and returns the first element of the array
  • letterPositions(sentence): Takes in a string and returns an object with each different letter as a key with all their respective indices positions for the assigned values
  • map(array, callback): Takes in array to map and callback function. Returns an array of results of items from callback function.
  • middle(array): Takes in an array and returns middle-most element(s) of given array. If array has one or two elements, there is no middle and will return empty array. If array had odd number of elements, returns array with single middle element. If array has even number of elements, returns array with two most middle elements.
  • tail(array): Takes in an array and returns an array containing every element except the first element of the array.
  • takeUntil(array, callback): Takes in an array and a callback function and will return an array of items up until the element in original array returns truthy value for callback.
  • without(sourceArray, itemsToRemove): Takes in a source array and an itemsToRemove array. Returns a new array with only elements from source array that were not present in the itemsToRemove array.