1.0.0 • Published 4 years ago
@tangivan/lotide v1.0.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 @tangivan/lotide
Require it:
const _ = require('@tangivan/lotide');
Call it:
const results = _.tail([1, 2, 3]) // => [2, 3]
Documentation
The following functions are currently implemented:
tail(arr): Take in an array and return themiddle(arr): Take in an array and return the middle-most element(s) of the given array.flatten(arr): Take in an array containing elements including nested arrays of elements, and return a "flattened" version of the array.map(array, callback)): Takes in anarrayandcallbackfunction. Returns a new array with the results of the callback function.takeUntil(array, callback): Takes in anarrayandcallbackfunction. Returns a slice of the array up to the first truthy value returned fromcallbackwithout(source, itemsToRemove): Takes in asourcearray and anitemsToRemovearray. Returns an array without items fromitemsToRemoveand only the leftover items insource.assertArraysEqual(actual, expected): Assertion function for arrays which takes in theactualarray and anexpectedarray. Return assertion messages in the console on whether they passed or failed the test.assertEqual(expected, actual): Assertion function for primitive data types which takes in theactualvalue and anexpectedvalue. Return assertion messages in the console on whether they passed or failed the test.assertObjectsEqual(actual, expected): Assertion function for objects which takes in theactualobject and anexpectedobject. Return assertion messages in the console on whether they passed or failed the test.countLetters(string): Take in a string and return an object with the individual characters as the key and the count of said characters as the value.countOnly(allItems, itemsToCount): Take in an array of itemsallItemsand return a count ofitemsToCountonly.eqArrays(arr1, arr2): Take in 2 arrays and returntrueif their contents are equal, orfalseif their contents are not equal.eqObjects(obj1, obj2): Take in 2 objects and returntrueif their contents are equal, orfalseif their contents are not equal.findKey(obj, callback): Takes in an object and a callback. Returns the first key for which the callback returns a truthy value. If no key is found, then it should returnundefinedfindKeyByValue(obj, val): Takes in an objectobjand a valuevaland returns thekeyof the input object which holds the input value.letterPositions(string): take in a stringstringwhich will return all the indices (zero-based positions) in thestringwhere each character is found.
1.0.0
4 years ago