jamie-huff-lotide
v1.0.0
Published
A library of functions made for lighthouse labs.
Downloads
4
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 @jamie-huff/lotide
Require it:
const _ = require('@jamie-huff/lotide');
Call it:
const results = _.tail([1, 2, 3], expected result) // => [2, 3]
Documentation
The following functions are currently implemented:
head(array)
: Given an array, will return the first value
tail(array)
: Given an array, will return all values but the first
middle(array)
: Return the middle two values of an array, 2 numbers for even length arrays
assertArrayEqual(array1, array2)
: Check if arrays are equal returns a statement depending on the answer
assertEqual(actual, expected)
: Check if actual and expected values are equal
assertObjectEqual(object1, object2)
: Check if objects are equal and returns a statement depnding on the answer
`countOnly(allItems, itemsToCount)' : Takes in an array of items, and an object. returns an object containing only those items that had 'true' beside them inside of the itemsToCount object, aswell as the number of those items.
ex: (allitems = bob, bob, carl, carl) ex: (itemsToCount = "bob": true, "carl": false) would return bob : 2
eqArrays(array1, array2)
: Check if two arrays are equal, includes nested arrays. Returns T / F
eqObjects(object1, object2)
: Check if two objects are equal, includes nested objects. Returns T / F
findKey(object, callback)
: Takes in an object, and callback function, returns the first the key of the object, from the first time the specificed value / name appears.
ex:
const results1 = findKey({ "Blue Hill": { stars: 1 }, "Akaleri": { stars: 3 }, "noma": { stars: 2 }, "elBulli": { stars: 3 }, "Ora": { stars: 2 }, "Akelarre": { stars: 3 } }, x => x.stars === 2)
would give us back // => "noma"
findKeyByValue(object, value)
: Returns the key of a specifced value from an object.
flatten(array)
: Removes nested arrays. [1, 2, [3, 4]] === [1, 2, 3, 4]
letterPositions(array, callbackfunction)
: Takes an an array of values and a callback function, returns a specificed array of values depending on what information is in the callback. Ex:
let words = ["ground", "control", "to", "major", "tom"]; let results1 = map(words, word => word[0]); results 1 = ["g", "c", "t", "m", "t"]
takeUntil(array, callback)
: Returns values of an array until a specificed condition in callback is met
without(array1, array2)
: Takes in 2 arrays, what ever values are present in array 2 will be removed, array 1 will be returned with those values removed.