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 element -
middle(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 number -
assertArraysEqual(actual,expected)
: compares theactual
value of an array to theexpected
value of an array and logs the result to the console -
assertEqual(actual,expected)
: compares theactual
value of to theexpected
and logs the result to the console -
assertObjectsEqual(actual,expected)
: compares theactual
value of an object to theexpected
value of an object and logs the result to the console -
countLetter(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 string -
countOnly(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
function -
findKeyByValue(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