@mbieganek/lotide v1.0.1
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 @mbieganek/lotide
Require it:
const _ = require('@mbieganek/lotide');
Call it:
const results = _.tail([1, 2, 3]) // => [2, 3]
Functions
The following functions are currently implemented:
assertArraysEqual(array1, array2) ⇒ boolean
Function that compares 2 arrays for equality and prints out a message telling us if they match or not
Kind: global function
Returns: boolean - The result of the evaluation
Param | Type | Description |
---|---|---|
array1 | Array.<(string|number|boolean)> | The first array to compare |
array2 | Array.<(string|number|boolean)> | The second array to compare |
assertEqual(actual, expected) ⇒ string
Function that compares 2 values for equality and prints out a message telling us if they match or not
Kind: global function
Returns: string - Prints message with match outcome
Param | Type | Description |
---|---|---|
actual | string | number | boolean | The first item to compare |
expected | string | number | boolean | The second item to compare |
assertObjectsEqual(actual, expected)
Function that compares 2 objects for equality and prints out a message telling us if they match or not
Kind: global function
Param | Type | Description |
---|---|---|
actual | Object | The first item to compare |
expected | Object | The second item to compare |
countLetters(string) ⇒ Object
Function that counts the total instances of a letter in a string
Kind: global function
Returns: Object - An object with characters from string
as
value labels, and the total instances of that character as the value
Param | Type | Description |
---|---|---|
string | string | The string containing the elements you wish to count |
countOnly(allItems, itemsToCount) ⇒ Object
Function that when given an array and an object, it will return an object containing counts of everything that the input object listed
Kind: global function
Returns: Object - A list of values found, and their total occurrences
Param | Type | Description |
---|---|---|
allItems | Array.<string> | Array of strings to look through |
itemsToCount | Object | Object with key value pairs specifying what to count |
itemsToCount.key | string | All keys in itemsToCount match the value to find as the key name, with a boolean value indicating if the name will be counted. For example, to count John assign a property in itemsToCount of John: true |
Example
When `allitems` is `['Karl', 'Fang', 'Salima', 'Fang']` and
`itemsToCount` is `{ Karl: false, Salima: true, Fang, true}` the
result will be `{ Salima: 1, Fang: 2 }`
eqArrays(array1, array2) ⇒ boolean
Function that compares 2 arrays for equality and returns the result
Kind: global function
Returns: boolean - The result of the evaluation
Param | Type | Description |
---|---|---|
array1 | Array.<(string|number|boolean)> | The first array to compare |
array2 | Array.<(string|number|boolean)> | The second array to compare |
eqObjects(object1, object2) ⇒ boolean
Function that evaluates two provided objects for equality
Kind: global function
Returns: boolean - The outcome of the evaluation
Param | Type | Description |
---|---|---|
object1 | Object | The first object to evaluate |
object2 | Object | The second object to evaluate |
findKey(object, action) ⇒ string | undefined
Function that scans an object and returns the first key for which
the callback/predicate returns a truthy value. If no key is found,
then it returns undefined
.
Kind: global function
Returns: string | undefined - The name of the key, or undefined if
none was found
Param | Type | Description |
---|---|---|
object | Object | The object from which to find a key |
action | function | The callback function that is used to evaluate the keys |
findKeyByValue(object, keyValue) ⇒ string | undefined
Function that takes in an object and a value. It should scan the object and return the first key which contains the given value
Kind: global function
Returns: string | undefined - The name of the key that matches, or undefined if
no match was found
Param | Type | Description |
---|---|---|
object | Object | The object to search |
keyValue | string | number | boolean | The value to search for |
flatten(array, buffer) ⇒ Array
Function that flattens an array with any number of nested arrays
Kind: global function
Returns: Array - The flattened array
Param | Type | Description |
---|---|---|
array | Array | The array of elements to flatten |
buffer | Array | used as a pass-through value for recursion |
head(array) ⇒ * | undefined
Function that returns the first element from an array, or undefined if the array was empty
Kind: global function
Returns: * | undefined - The first element from the array, or undefined
Param | Type | Description |
---|---|---|
array | Array | An array containing one or more elements |
letterPositions(sentence) ⇒ Object
Function that receives a string, and returns an object with a key for each unique character, as well the character positions in the string
Kind: global function
Returns: Object - An object with a key matching each unique
character, and where to find them in the sentence
Param | Type | Description |
---|---|---|
sentence | string | The string to analyze |
map(array, callback) ⇒ Array
Function that will take in two arguments, an array to map, and a callback function. The function will return a new array based on the results of the callback function.
Kind: global function
Returns: Array - An array with the results of the callback function
Param | Type | Description |
---|---|---|
array | Array | An array to map |
callback | function | A callback function to call against each item in the array |
isEven(number) ⇒ boolean
Function that evaluates a number as even
Kind: global function
Returns: boolean - The outcome of the evaluation
Param | Type | Description |
---|---|---|
number | number | The number to evaluate as even |
middle(array) ⇒ * | undefined
Function that returns the middel elemet(s) from an array, or undefined if the array was empty
Kind: global function
Returns: * | undefined - The first element from the array, or undefined
Param | Type | Description |
---|---|---|
array | Array | An array containing three or more elements |
printAssertEqualResult(hasEquality, actual, expected) ⇒ string
Function that builds a message for the assertEqual functions in this library
Kind: global function
Returns: string - A formatted message
Param | Type | Description |
---|---|---|
hasEquality | boolean | Result of equality check |
actual | * | Input passed to the equality check |
expected | * | Expected input in the equality check |
tail(array) ⇒ Array
Function that returns all but the first element from an array, or undefined if the array was empty. If the array is empty or only has one element, it returns an empty array
Kind: global function
Returns: Array - All but the first element from the array, or an empty
array
Param | Type | Description |
---|---|---|
array | Array | An array containing one or more elements |
takeUntil(array, callback) ⇒ Array
Function that returns a slice of the provided array with elements taken from the beginning, up until the callback/predicate returns a truthy value
Kind: global function
Returns: Array - The elements that were sliced from the input array
Param | Type | Description |
---|---|---|
array | Array | The array from which to slice elements |
callback | function | The predicate function determines when to stop slicing elements from the array |
without(sourceItems, removeItems) ⇒ Array
Function that copies the source
array, while excluding items that
are found in the removeItems
array
Kind: global function
Returns: Array - The copied array
Param | Type | Description |
---|---|---|
sourceItems | Array.<(string|number|boolean)> | The array to be copied |
removeItems | Array.<(string|number|boolean)> | An array of items to not include in the returned array |
Credits
The functions section of this README was generated with jsdoc2md a suite of modules for generating markdown documentation from jsdoc-annotated source.