1.0.0 • Published 5 years ago
@duncan-mann/sharedlotide 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 Alex and Duncan as part of our learnings at Lighthouse Labs.
Usage
Install it:
npm install @lxg1992/SharedLotide
Require it:
const _ = require('@lxg1992/SharedLotide');
Call it:
const results = _.tail([1, 2, 3]) // => [2, 3]
Documentation
The following functions are currently implemented:
head(array)
: returns the first element of anarray
tail(array)
: returns thearray
without the first elementmiddle(array)
: ifarray
has even number of elements, returns an array of two middle numbers, otherwise if array has odd number of elements, returns an array of a middle numberassertArraysEqual(actual,expected)
: compares theactual
value of an array to theexpected
value of an array and logs the result to the consoleassertEqual(actual,expected)
: compares theactual
value of to theexpected
and logs the result to the consoleassertObjectsEqual(actual,expected)
: compares theactual
value of an object to theexpected
value of an object and logs the result to the consolecountLetter(string)
: takes in astring
and returns an object with the keys each being a letter that is encountered in thestring
and the value of each said key being the number of times that letter is encountered in the stringcountOnly(arrayOfValues, objectOfItemsToCount)
: returns an object that has the number of times each key ofobjectOfItemsToCount
is encountered inarrayOfValues
eqArrays(array1, array2)
: returnstrue
ifarray1
is found equal toarray2
, otherwise returnsfalse
eqObjects(object1, object2)
: returnstrue
ifobject1
has the same keys and values asobject2
, otherwise returnsfalse
findKey(object, callback)
: returns the first item within anobject
which returns true when tested against thecallback
functionfindKeyByValue(objectToScan, valueToUse)
: Takes anobject
and a specifiedvalue
, and returns the first key within theobject
that has this specifiedvalue
.flatten(toFlatten)
: Takes a nested array and returns an array with one layer.map(array, callback)
: Takes an array and a callback function. The callback function applies an action to each element of the array, and returns a new array with the results.takeUntil(array, callback)
: receivesarray
andcallback
function. The callback function will assess each value within the inputed array until callback(value) returns true. takeUntil will then a return a new array, containing all of the inputed values up until that value.without(source, itemsToRemove)
: takes asource
array and aitemsToRemove
array, and removes the values withinitemsToRemove
from thesource
array
1.0.0
5 years ago