1.1.0 • Published 4 years ago

@khnrv/lotide v1.1.0

Weekly downloads
144
License
ISC
Repository
github
Last release
4 years ago

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

ParamTypeDescription
actualArrayarrayArray to test
expectedArrayarrayArray expected

assertEqual(actual, expected)

Compare two value and print out if they match or not

ParamTypeDescription
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

ParamTypeDescription
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.

ParamTypeDescription
stringToCountstringSentece 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.

ParamTypeDescription
allItemsarrayan array of strings that we need to look through
itemsToCountobjectan 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

ParamTypeDescription
firstArrayarray-
secondArrayarray-

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!

ParamType
object1object
object2object

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.

ParamType
objectobject
callbackcallback

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.

ParamType
objectToSearchobject
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.

ParamTypeDescription
arrayToFlattenarrayArray to flatten

head(inputArray) ⇒ *

Output the value at index 0 of a given array

Returns: * - Value at index 0 of the input array

ParamTypeDescription
inputArrayarrayInput 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.

ParamTypeDescription
sentencestringSentence 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.

ParamTypeDescription
arrarrayArray to map
callbackcallbackEdit 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

ParamTypeDescription
arrayToAnalysearrayArray 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)

ParamTypeDescription
inputArrayarrayInput 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

ParamType
arrayarray
callbackcallback

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

ParamTypeDescription
arrayToEditarrayArray where to remove element from
itemsToRemovearrayArray of elements to remove from the arrayToEdit
1.1.0

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago