Skip to content

luisitoguanes/js_utility_library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn


JS utility library implementation

It implements some of the most commons functions of utility library like Lodash

Report Bug · Request Feature

Table of Contents

  1. About The Project
  2. Getting Started
  3. Usage
  4. License
  5. Contact
  6. Acknowledgements

About The Project

It implements some of the most commons functions of utility library like Lodash

Built With

  • Javascript

Getting Started

To get a local copy up and running follow these simple steps.

Installation

  1. Clone the repo
    git clone https://github.com/luisitoguanes/js_utility_library.git

Usage

import _ from utils.js

Each: Receives an array or an object and a callback function. It will loop on each element and the callback will receive the current object being looped, the index, and the entire list. Doesn't return anything, it only executes the callback.

const arr = [1, 2, 3];
_.each(arr, (element) => { console.log(element);}); // 1 2 3

Filter: Receives an array or an object and a callback function. It will loop on each element and the callback will receive the current object being looped, the index, and the entire list. The callback must return true or false Will return an array with the objects that returned true from the callback.

const arr = [1, 2, 3];
const arrayLowerThanTwo = _.filter(arr, (element) => { if(element<=2) { return true; } else { return falses;}}); 
//  returns [1, 2]

Map: Receives an array or an object and a callback function. It will loop on each element and the callback will receive the current object being looped, the index, and the entire list. Will return an array with the same length that the original array (or object keys) with the value transformed from the callback.

const arr = [1, 2, 3];
const arrayElementPlusOne = _.map(arr, (element) => { return element + 1;}); 
//  returns [2, 3, 4]

Reduce: Receives an array or an object, a callback function, and an initial value. It will loop on each element and the callback will receive the current object being looped, the index, and the entire list. Return ONE object that accumulates the result of each iteration of the callback

const arr = [1, 2, 3];
const accumulative = _.reduce(arr, (element) => { return element + 1;}, 0); 
//  returns 6

License

Distributed under the MIT License.

Contact

Luis Guanes - @luisitoguanes - [email protected]

Project Link: https://github.com/luisitoguanes/js_utility_library

Acknowledgements

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published