@shaheerahmed/lotide

A mini clone of the Lodash library for learning purposes

Usage no npm install needed!

<script type="module">
  import shaheerahmedLotide from 'https://cdn.skypack.dev/@shaheerahmed/lotide';
</script>

README

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

Require it:

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

Call it:

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

Documentation

The following functions are currently implemented:

  • head(...): returns the first element of an array (i.e., the head)
  • tail(...): returns all elements in an array except the first one as a new array
  • middle(...): returns the middle element in an array of numbers if length is odd, otherwise returns the middle element - 1 and the middle element (both as a new array)
  • flatten(...): returns a flattened array if an array is nested (regardless of nest-level), otherwise returns the array
  • countLetters(...): returns the occurence-count of each letter in a string as an object
  • countOnly(...): returns the middle element in an array if it is odd, otherwise returns the middle element - 1 and the middle element as an object
  • eqArrays(...): returns a boolean after comparing the contents of two arrays
  • eqObjects(...): returns a boolean after comparing the contents of two objects
  • findKey(...): returns a key if a passed in callback function manipulating the key-value evalutes to true otherwise returns undefined
  • findKeyByValue(...): returns a key when passed an object and the object contains a passed-in object-key-value
  • letterPositions(...): stores the index of each character of a passed-in string and then returns the index of all occurrences of that desired character in an array
  • map(...): returns a flattened array regardless of nest-level
  • takeUntil(...): takes elements from an array until the conditions of a passed-in function satisfied
  • without(...): takes a source array and a items to remove array and returns a new array with items to remove elements removed from the source array
  • assertEqual(...): asserts a message after comparing the contents of two primitive values
  • assertArraysEqual(...): asserts a message after comparing the contents of two arrays
  • assertObjectsEqual(...): asserts a message after comparing the contents of two objects