1.0.0 • Published 1 year ago

@kcho15/lotide v1.0.0

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 me as part of my learnings at Lighthouse Labs.

Usage

Install it:

npm install @kcho15/lotide

Require it:

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

Call it:

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

Documentation

The following functions are currently implemented:

  • head(array) : Returns the first element of an array input

  • tail(array) : Returns all the elements of an array except the first element

  • middle(array) : Returns the middle element/elements from an array ex1: returns 2 from input 1, 2, 3 ex2: returns 2, 3 from input 1, 2, 3, 4

  • findKey(object, callback) : Returns the first key in an object that satisfies the callback function ex: findKey({ "Blue Hill": { stars: 1 }, "noma": { stars: 2 } }, x => x.stars === 2) // Returns "noma"

  • map(array, callback) : Returns a new array with the callback function applied ex: const words = ["ground", "control", "to", "major", "tom"] map(words, word => word.toUpperCase()), // Returns ['GROUND', 'CONTROL', 'TO', 'MAJOR', 'TOM']

  • countLetters(string) : Returns a count of the letters in a given string as an object ex: countLetters("LHL") // Returns { L: 2, H: 1 }

  • without(array, removedElement) : Returns a new array with the element specified removed
    ex: without(["hello", "world", "lighthouse"], ["lighthouse"]) // Returns ["hello", "world"]

  • takeUntil(array, callback) : Returns a new array up to the point of the callback function ex: const data = [1, 2, 5, 7, 2, -1, 2, 4, 5]; takeUntil(data, x => x < 0) // Returns [1, 2, 5, 7, 2]

  • eqArrays(array1, array2) : Returns true if two input arrays are equal in length and values ex: eqArrays([1, 2, 3], [1, 2, 3]) // Returns true

1.0.0

1 year ago