@jdhal056/lotide v1.0.0
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 @jdhal056/lotide
Require it:
const _ = require('@jdhal056/lotide');
Call it:
const results = _.tail([1, 2, 3]) // => [2, 3]
const results = _.head([1, 2, 3]) // => [1]
const results = _.middle([1, 2, 3]) // => [2]
const results = _.without([1, 2, 3], [2]) // => [1, 3]
const results = _.takeUntil([1, 2, 5, 7 2, -1, 2, 4, 5], x => x < 0) // => [1, 2, 5, 7, 2]
const results = _.map(["ground", "control", "to", "major", "tom"], x => word[0]) // => ["g","c","t","m","t"]
const results = _.letterPositions("hello").l // => [2, 3]
const results = _.flatten([1, [2], [3, 4], 5]) // => [1, 2, 3, 4, 5]
const results = _.findKeyByValue({sci_fi: "The Expanse", comedy: "Brooklyn Nine-Nine", drama: "The Wire"}, "The Wire") // => "drama"
const results = _.findKey({"Blue Hill": { stars: 1 }, "Akaleri": { stars: 3 }, "noma": { stars: 2 }, "elBulli": { stars: 3 }, "Ora": { stars: 2 }, "Akelarre": { stars: 3 }}, x => x.stars === 2) // => "noma"
const results = _.eqObjects({a: "1", b: "2"}, {a: "1", b: "2"}) // => true
const results = _.eqArrays([1, 2, 3], [1, 2, 3]) // => true
const results = _.countOnly(["Karl", "Salima", "Agouhanna", "Fang", "Kavith", "Jason", "Salima", "Fang", "Joe"], {"Jason": true, "Karima": true, "Fang": true}) // => {Fang: 2, Jason: 1}
const results = _.countLetters("the Octopus is purple") // => {t: 2, h: 1, e: 2, O: 1, c: 1, o: 1, p: 3, u: 2, s: 2, i: 1, r: 1, l: 1}
Documentation
The following functions are currently implemented:
tail(array)
: returns the array without the first elementhead(array)
: returns the array with only the first elementmiddle(array)
: returns the middle element of an array (middle 2 if even number of elements)without(items, unwantedItems)
: returns an array of items after removing unwanted itemstakeUntil(array, callback)
: returns an array with all elements until the callback condition is metmap(array, callback)
: returns an array after calling the callback on each elementletterPositions(sentence)
: returns an object with the index position of the specific characterflatten(array)
: returns a flattened array(not nested) when given a nested arrayfindKeyByValue(object, value)
: returns the key that holds the specified valuefindKey(object, callback)
: returns the specified key after calling the callback functioneqObjects(object1, object2)
: compares two objectseqArrays(array1, array2)
: compares two arrayscountOnly(allItems, itemsToCount)
: returns an object with the count of the given items to count within an objectcountLetters(string)
: returns an object with the count of all letters in a string
5 years ago