1.0.1 • Published 1 year ago
@patrick-tumu/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 @patrick-tumu/lotide
Require it:
const _ = require('@patrick-tumu/lotide');
Call it:
const results = _.tail([1, 2, 3]) // => [2, 3]
Documentation
The following functions are currently implemented:
head(array)
: return the first element of a non empty array if input array is empty return undefinedtail(array)
: return the elements of an array - the first element of an array with length greater than 1 otherwise return empty arraymiddle(array)
: if an array is odd return the middle value, if an array if even in length return the average of the middle two values, if the array has a length <= 2 return an empty arraycountLetters(string)
: takes in a string and returns an object where the letters of the input string become keys and the values are the number of times they occur in the stringcountOnly(array)
: takes in an array and a value. Returns an object where the value is a key and the paired value of that key is the number of times the input value occurs in the input arrayeqArrays(array1, array2)
: takes in two arrays returns true if equal and false otherwiseeqObjects(obj1, obj2)
: takes in two objects returns true if equal and false otherwisefindKey(obj1, callback)
: takes in an object and iterates through the object passing each value into the callback function. Can be used to find key depending on the callback usedfindKeyByValue(obj1, value)
:takes in an object and a value returns the key of the object associated with input value or undefinedmap(array, callback)
:takes in an array and a callback function. iterates through the array and returns a new array where every value of input array has been passed into the callback function and pushed in to the result arrayletterPostions(string)
:takes in a string and returns an object where the letters of the string are the keys and the posistions in which they appear in the original string are the values associated (array).takeUntil(array, callback)
: takes in an array and a callback function returns an array of the original values until one of the original values when passed to the callback returns falsemin(array)
:takes in an array of numbers and returns a number representing the index where the smallest number is