@hatem.deux/lotide v1.0.2
Lotide
A mini-clone of the Lodash library.
Author :
Hatem : Github: @AH82 | npm: @hatem.deux
Author's Notes :

- This project is a part of a learning experience as a student at Lighthouse Labs's Full-Stack Web-Developper Bootcamp course.
- This is my very first project.
- Main focus:
- Data manipulation (arrays and objects)
- Callbacks
- Recursion
- export / import (
require) - TDD / BDD with Mocha & Chai
- Most commented-out code is kept intentionally for learning, improvement & future awareness purposes.
- These are especially at the bottom of Test files.
- This project was revisited post-bootcamp and implemented additional excercises, did major clean up and fixed a couple of bugs.
Table of contents
Setup
CAUTION: This library is published as a part of a learning process. It is not meant for use in serious projects.
Install via npm:
In your Terminal:
> npm install @hatem.deux/lotideAt the top of your JavaScript code:
const _ = require('@hatem.deux/lotide');Call it (example):
const results = _.tail([1, 2, 3]) // => [2, 3]Clone it from GitHub
in your terminal:
> git clone git@github.com:AH82/lotide.gitDependencies
Install Dependencies in the terminal:
> npm installDevDependencies
> npm install --save-dev mocha chaiDocumentation
Main Functions
- All functions are in files of
"./<function name>.js" index.jsexports all these functions.
| Function name | parameter | Description |
|---|---|---|
head | array | returns the value of the first (head) element in an array. |
tail | array | returns an array of remaining element in an array. |
middle | array | returns an array of middle element(s) in an array (1 for odd, 2 for even). |
without | SourceArray, itemsToRemoveArray | returns a filtered-out new array. |
flatten | array | returns a flattened array from a multi-level nested one in the same element-order (i.e. removes nesting) |
countOnly | array, itemsToCountObject | returns an object containing counts of everything the input object listed. |
countLetters | string | returns an object a count of each of the letters in that sentence. ignores whitespaces. |
letterPositions | string | returns an object with all the indices (zero-based positions) in the string where each character is found. (property-value is an array) |
findKeyByValue | object, value | scans the 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. |
map | array, callback | returns an array modified by the callback. |
takeUntil | array, callback | returns a slice of the array with elements taken from the beginning until callback returns a truthy value. |
findKey | object, callback | returns the first key for which the callback returns a truthy value. If not found, returns undefined. |
|
Comparison functions
These functions are not included in index.js.
| Function name | parameter | Description |
|---|---|---|
eqArrays | array1, array2 | deep-compares arrays. returns true if identical. false if not. |
eqObjects | object1, object2 | deep-compares objects. returns true if identical. false if not. |
Custom Assertion functions
These functions are not included in index.js.
These functions were used during development and are no longer required by other functions. They are kept for archiving and the learning experience.
These are side-effects function do not return, they produce console.logs indicating success or failure of Assertion.
They typically use the Comparison functions as inputs to assert.
| Function name | parameter | Description |
| -------------------- | :-----------------------------: | ----------- |
| assertEqual | bool | for regular values
| assertArraysEqual | bool | for arrays
| assertEqualObjects | bool | for objects
|
Testing
Using Mocha/Chai
- All test files are under
"./test/"- except "Custom Assertion functions" intentionally placed under
"./test/customAssertTests"to be ignored by test run.
- except "Custom Assertion functions" intentionally placed under
- All Test files are named by the convention
"./test/<function name>Test.js"
Running Test
- At project root folder in the terminal
> mochaor
> npm testChange History
v1.0.2
- upgrades to version 1.0.2 to fix an npm unpublishing/publishing accidental issue.
- fixes a minor issue in the interlinks of REAMDME.md
v1.0.1
Improvements
eqArrays&eqObjectsnow support deep comparison (through recursion)README.mdredesigned.- lints, cleans and removes redundant, dead or commented-out code across entire project, except when intentional.
- Testing
- The entire code is now covered by tests.
- Any in-file custom tests (console.log or custom assertions) moved to the
"./test/*"folders. - Any remaining custom tests are converted to Mocha/Chai code.
- except: custom Assertions due to side-effect nature (but rapped in Mocha's describe/it )
Bug fixes
takeUntil.js- Issue: returns undefined if the callback argument does not match an element. (i.e. does not find a truthy element).
- Fix: returns the entire array if no match.
without.js- Issue: Does not return a new array. (i.e. modifies the original).
- Fix: returns a new array.
index.js- fixes typo:
=>findKeysByValuefindKeyByValue
- fixes typo:
package.json- Issue:
"main"refered to the incorrect file =>{ ..., "main": "assertArraysEqual.js", ... } - Fix:
"main"now referes to the correct file =>{ ..., "main": "index.js", ... }
- Issue:
- functions
findKeysByValue,letterPositions,map,takeUntil,without,findKeyare now implemented. (on npm package only)
v1.0.0
- Initial release.
Meet Larry The Duck - Lighthouse labs mascot
