1.0.0 • Published 4 years ago

@sameerk-dev/lotide v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
4 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 @sameerk-dev/lotide

Require it:

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

Call it:

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

Documentation

The following functions are currently implemented:

  • assertArraysEqual(...): Outputs assertions. Compares two input arrays using eqArrays function and consoles.log assertions if arrays match or not. Does not take into account nested arrays, i.e only useful for 1D array inputs.
  • assertEqual(...): Compares input primitive data type values of (actual) and (expected) to see if they match, and prints out assertion based on result.
  • assertObjectsEqual(...): Outputs assertions. Will take in two input objects and makes use of eqObjects function to assert if objects are matching (both have same keys and values) or not. Doesn't work for nested objects, only 1D objects.

  • countLetters(...): Takes in a sentence (as a string) and then return a count of each of the letters in the sentence. Output is an object with keys representing characters in string, and values as counts.

  • countOnly(...): This function should take in a collection of items and return counts for a specific subset of those items. Given an Array as list of items and an Object with keys corresponding to specific items with values as true (i.e should be counted) or false should be ignored. Output is object with subset of counted items.
  • eqArrays(...): Takes two arrays and returns true or false, based on a perfact match. Only works with 1D arrays of primitive data types. Not useful for nested arrays.
  • eqObjects(...): Will take in two 1D objects (objects can't have nested objects or nested arrays as values) and returns true or false, based on a perfect match. Returns true if both objects have identical keys with identical values.
  • findKey(...): Takes in an object (1D not nested values) and a callback. It scans the object and returns the first key for which the callback returns a truthy value/match found. If no key is found, then it returns undefined.
  • findKeyByValue(...): Takes in an object and a value. Scans the object and returns the first key which contains the given value. If no key with that given value is found, then it returns undefined.
  • flatten(...): Given an array with other arrays inside (nested), flatten it into a single-level array that is outputted.
  • head(...): This function returns the first/head element of a given array that is sent as input.
  • index(...): Includes all functions as exportable functions in single file.
  • letterPositions(...): Inputs: a string (sentence). Output: an object of arrays. The keys are the individual characters found in the string. The values of the keys are the arrays holding the indices of where that key is found inside the string.
  • map(...): An array to map with a callback function. Will return a new array based on the results of the callback function.
  • middle(...): Will take in an array and return the middle-most element(s) of the given array. If even number of elements in array - will return array of two middle numbers, else if odd will return array with single middle element.
  • tail(...): Takes an array and returns the tail (i.e all elements excluding the first head element);
  • takeUntil(...): The function will return a "slice of the input array with elements taken from the beginning." It should keep going until the callback/predicate returns a truthy value.
  • without(...): Will return a subset of a given array, removing unwanted elements. Nested arrays and objects are excluded from scope (i.e the input arrays should hold primitive data types only).