1.0.0 • Published 2 years ago

@gonzonieto/lotide v1.0.0

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

Lotide

It's like Lodash but worse.

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

Require it:

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

Call it:

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

Documentation

The following functions are currently implemented:

flatten head index letterPositions map middle tail takeUntil without

  • eqArrays(array1, array2): Deep array equality check. Returns false if array lengths are not equal, or if any two items of same index are not equal to each other; otherwise returns true. Not recursive so nested arrays will trip it up.
  • assertEqual(actual, expected): Logs to console whether the arguments are equal to each other or not.
  • assertArraysEqual(actual, expected): Logs both arrays to the screen followed by an assertion as to whether they are deeply equal to each other. Uses eqArrays()
  • assertObjectsEqual(actual, expected): Uses eqObject() assert whether two objects are deeply equal.
  • eqObjects(actual, expected): Deep object equality check. Returns false if they have a different number of keys, or if the value of a given key is different. Uses eqArrays() if both values are arrays, or calls itself recursively if both values are non-array objects.
  • countLetters(phrase): Returns an object whose keys are characters and values are how many times each character appeared in phrase.
  • countOnly(itemsArray, itemsToCount): Takes an array of items and an object whose keys are the string being sought in the array and the value is a boolean indicating whether that string is being sought. Returns an object whose keys are the strings being sought and values are the frequency they occurred in itemsArray
  • findKey(object, callback): Returns the first key for which callback(objectkey) returns true
  • findKeyByValue(object, value): Returns the first key whose value matches value
  • flatten(array): Recursive function that takes an array of any depth of nested and returns a 1-D array
  • head(array): Returns the first item of array
  • letterPositions(sentence): Returns an object whose keys are each character in sentence and values are which positions they appeared in
  • map(array, callback): Returns an array containing the result of running callback() on each array item
  • middle(array): Returns an array containing the middle item of an array. Returns [] for arrays of length <= 2, and returns an array with the two middle items of the input array if it had an even number of items
  • tail(array): Returns an array from 1..end of the input array, cutting off the head
  • takeUntil(array, callback): Returns an array containing all items of the input array which precede the first item for which callback(item) is true. Returns [] if callback(item) is true for the first item.
  • without(source, itemsToRemove): Returns an array containing the items of source that are not in itemsToRemove.