@khnrv/lotide v1.1.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 @khnrv/lotide
Require it:
const _ = require('@khnrv/lotide');
Call it:
const results = _.tail([1, 2, 3]) // => [2, 3]
Documentation
The following functions are currently implemented:
assertArraysEqual(actualArray, expectedArray)
Function that takes in two arrays and print out if they match or not
| Param | Type | Description |
|---|---|---|
| actualArray | array | Array to test |
| expectedArray | array | Array expected |
assertEqual(actual, expected)
Compare two value and print out if they match or not
| Param | Type | Description |
|---|---|---|
| actual | * | Enter the variable to test |
| expected | * | Enter the expected value of the variable |
assertObjectsEqual(actual, expected)
This function compares two objects and print out if they match or not
| Param | Type | Description |
|---|---|---|
| actual | * | Enter the object to test |
| expected | * | Enter the expected object |
countLetters(stringToCount)
This function takes in a sentence (as a string) and then return a count of each of the letters in that sentence.
| Param | Type | Description |
|---|---|---|
| stringToCount | string | Sentece to count (only alphbetical characters will be counted) |
countOnly(allItems, itemsToCount)
Function, given an array and an object, return an object containing counts of everything that the input object listed.
| Param | Type | Description |
|---|---|---|
| allItems | array | an array of strings that we need to look through |
| itemsToCount | object | an object specifying what to count |
eqArrays(firstArray, secondArray) ⇒ boolean
Function that takes in two arrays and returns true or false, based on a perfect match.
Returns: boolean - Return whether the arrays are identical
| Param | Type | Description |
|---|---|---|
| firstArray | array | - |
| secondArray | array | - |
eqObjects(object1, object2) ⇒ boolean
This function takes in two objects and returns true or false, based on a perfect match.
Returns: True if both objects have identical keys with identical values. Otherwise you get back a big fat false!
| Param | Type |
|---|---|
| object1 | object |
| object2 | object |
findKey(object, callback)
This function takes in an object and a callback. It scans the object and returns the first key for which the callback returns a truthy value. If no key is found, then it returns undefined.
| Param | Type |
|---|---|
| object | object |
| callback | callback |
findKeyByValue(objectToSearch, valueToFind)
This function scan a given object and return the first key which contains the given value. If no key with that given value is found, then it should return undefined.
| Param | Type |
|---|---|
| objectToSearch | object |
| valueToFind | * |
flatten(arrayToFlatten)
This function will take in an array containing elements including nested arrays of elements, and return a "flattened" version of the array.
| Param | Type | Description |
|---|---|---|
| arrayToFlatten | array | Array to flatten |
head(inputArray) ⇒ *
Output the value at index 0 of a given array
Returns: * - Value at index 0 of the input array
| Param | Type | Description |
|---|---|---|
| inputArray | array | Input an array to find its head |
letterPositions(sentence)
This function returns all the indices (zero-based positions) in the string where each character is found.
| Param | Type | Description |
|---|---|---|
| sentence | string | Sentence where to count letters |
map(arr, callback) ⇒ array
This function creates a new array populated with the results of calling a provided function on every element in the calling array.
| Param | Type | Description |
|---|---|---|
| arr | array | Array to map |
| callback | callback | Edit parameters |
middle(arrayToAnalyse) ⇒ array
This function takes in an array and return the middle-most element(s) of the given array.
Returns: array - - Middle element(s) of the given array
| Param | Type | Description |
|---|---|---|
| arrayToAnalyse | array | Array where to find the middle element(s) |
tail(inputArray) ⇒
For a given array, returns everything except for the first item (head).
Returns: - Returns a copy of the array without the first item (head)
| Param | Type | Description |
|---|---|---|
| inputArray | array | Input the array for which you want to return the tail |
takeUntil(array, callback)
This function keeps collecting items from a provided array until the callback provided returns a truthy value.
Kind: global function
| Param | Type |
|---|---|
| array | array |
| callback | callback |
without(arrayToEdit, itemsToRemove) ⇒ array
This function take in a source array and a itemsToRemove array. It return a new array with only those elements from source that are not present in the itemsToRemove array.
Returns: array - New array with only those elements from source that are not present in the itemsToRemove array
| Param | Type | Description |
|---|---|---|
| arrayToEdit | array | Array where to remove element from |
| itemsToRemove | array | Array of elements to remove from the arrayToEdit |