1.0.1 • Published 1 year ago

@jimmyzhng/lotide v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year 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 Jimmy Zhang as part of my learnings at Lighthouse Labs.

Usage

Install it:

npm install jimmyzhng/lotide

Require it:

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

Call it:

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

Documentation

The following functions are currently implemented:

  • head(arr): returns the first element of the array (at index 0)
  • tail(arr): returns all the elements of the array, except for the first one
  • middle(arr): returns the element found at the middle of the array. If the array's length is even, it will return the middle-most two.
  • assertArraysEqual(arr1, arr2): recursively compares two arrays. Logs to the console whether or not the assertion passed
  • assertObjectsEqual(obj1, obj2): recursively compares two objects. Logs to the console whether or not the assertion passed
  • countLetters(str): counts and returns the number of letters in a string
  • eqArrays: recursively compares two arrays
  • eqObjects: recursively compares two objects
  • findKey(obj, cb): scans the object, and returns the first key for which the callback function returns a truthy value. if none, return undefined.
  • findKeyByValue(obj, value): takes in an object and a value, and returns first key which contains the given value. If the value is not is found, it returns undefined
  • flatten(arr): takes in an array containing elements, including nested arrays of elements, and return a flattened version of the array
  • letterPositions: returns all the indices in the string where each character is found
  • map(arr, cb): takes in two arguments: an array to map, a callback function. Returns a new array based on the callback function
  • `takeUntil: takes in two arguments: an array to work with, and the callback function (Lodash calls this the predicate). Function returns an array, with a 'slice with elements taken from the beginning'. It will continue taking them away, until the callback returns a truthy value
  • without(arr, unwanted): returns a subset of an array, removing unwanted elements