1.0.71 • Published 10 months ago

collection-of-algos v1.0.71

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

A continuing collection of good to know algorithms mainly in JS

It's also a library that can be used in your projects. It contains algos that are both common and un-common.

codecov test License: MIT NPM Downloads

Edit example: collection of algos in reactjs

To use this package in your project

Installation Open your terminal or command prompt, navigate to your project directory and run the following command:

# using npm
npm install collection-of-algos

# using yarn
yarn add collection-of-algos

This will install version latest version of the package collection-of-algos.

Import For CommonJS (Node.js):

const algos = require('collection-of-algos');

For ES6 syntax:

import algos from 'collection-of-algos';

Usage

algos.nativeSort();

Import specific functions

import { bubbleSort, nativeSort } from 'collection-of-algos';

Usage

let exampleArr = [5, 3, 1, 4, 2];
// create shallow copy of the array
const unsortedArr = [...exampleArr];
const obj1 = { arr: unsortedArr };

// using a promise chain
bubbleSort(obj1).then(({ arr }) => {
  console.log(arr); // [1, 2, 3, 4, 5]
});

// or using async/await
const { arr: arrOfNums } = await bubbleSort(obj1);

console.log(arrOfNums); // [1, 2, 3, 4, 5]

const obj2 = {
  arr: [
    { name: 'John', age: 23 },
    { name: 'Mike', age: 32 },
    { name: 'Chris', age: 11 },
    { name: 'Nick', age: 19 },
  ],
  key: 'age',
};
const { arr: arrOfObjs } = await nativeSort(obj2);

console.log(arrOfObjs);
// [
//   { name: 'Chris', age: 11 },
//   { name: 'Nick', age: 19 },
//   { name: 'John', age: 23 },
//   { name: 'Mike', age: 32 },
// ]

In this code, bubbleSort and nativeSort are specific functions imported from the collection-of-algos package. bubbleSort is a sorting algorithm that's being applied to an array of numbers, while nativeSort is used to sort an array of objects by a specific key.

Remember, before using await, you should ensure that your code is inside an async function. The await operator is used to wait for a Promise. It can only be used inside an async function.

Work with this repo locally

In your terminal

# install dependencies
yarn

# serve the app
yarn dev

Running unit tests

# run all tests
yarn test

# for coverage report
yarn coverage

local server to test functions locally (Ctrl-C to stop)

http://localhost:3000

Connect with me

LinkedIn

/docs-dist (The visualizer codebase)

  • Currently contains the build dist for the documentation folder which is currently hidden.
  • Once it's in a good place I will makde it public.

Todos

  • Think about separating each algo into its own page
  • Add notes and drawings for each algo
  • Unit the helper functions
  • Docker support

Using Docker (WIP parcel watch is not working)

# build the docker image
docker-compose build

# serve the app
docker-compose up

# Stop & remove the container
docker-compose down
1.0.61

10 months ago

1.0.60

10 months ago

1.0.71

10 months ago

1.0.59

10 months ago

1.0.58

10 months ago

1.0.55

11 months ago

1.0.54

11 months ago

1.0.53

11 months ago

1.0.57

11 months ago

1.0.56

11 months ago

1.0.52

11 months ago

1.0.44

12 months ago

1.0.22

12 months ago

1.0.21

12 months ago

1.0.48

12 months ago

1.0.26

12 months ago

1.0.47

12 months ago

1.0.25

12 months ago

1.0.46

12 months ago

1.0.24

12 months ago

1.0.23

12 months ago

1.0.29

12 months ago

1.0.49

12 months ago

1.0.27

12 months ago

1.0.51

12 months ago

1.0.50

12 months ago

1.0.30

12 months ago

1.0.20

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago