GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - sumtype/common-algorithms-js: Common algorithms implemented in JavaScript.

This repository was archived by the owner on Dec 3, 2023. It is now read-only.
BranchesTags
Open more actions menu

Latest commit

 

History

78 Commits
78 Commits

Folders and files

NameName
Last commit message
Last commit date
algorithms
algorithms
 
 
locales
locales
 
 
test
test
 
 
.babelrc
.babelrc
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
ISSUE_TEMPLATE.md
ISSUE_TEMPLATE.md
 
 
LICENSE
LICENSE
 
 
PULL_REQUEST_TEMPLATE.md
PULL_REQUEST_TEMPLATE.md
 
 
README.md
README.md
 
 
es.js
es.js
 
 
es5.js
es5.js
 
 
package.json
package.json
 
 

Repository files navigation

Common Algorithms in JavaScript

Build Status Coverage Status Known Vulnerabilities JavaScript Style Guide npm

Common algorithms implemented in JavaScript with Mocha/Chai testing. Uses Babel and UMD to transpile algorithm modules from ES6+ to ES5. Test coverage reports are provided by nyc and piped to Coveralls. Coveralls reports coverage for ES6+ algorithms (although both ES6+ and transpiled ES5 algorithms are tested by Travis-CI). All JavaScript code follows JavaScript Standard Style guidelines. README translations are provided in the locales directory and translated with Google Translate. Currently Spanish, Hebrew, and Chinese are available. Contributions are welcome! Follow the guidelines.

Array

  • Binary Search
  • Bubble Sort
  • Bucket Sort
  • Cocktail Sort
  • Counting Sort
  • Durstenfeld Shuffle (a.k.a. Knuth Shuffle)
  • Gnome Sort
  • Insertion Sort
  • Linear Search
  • Merge Sort
  • Quick Sort
  • Radix Sort
  • Reservoir Sampling
  • Sattolo Cycle
  • Selection Sort
  • Shell Sort
  • Sleep Sort

Geometry

  • Bezier Curve
  • Ray-Casting

Graph

  • Breadth First Search
  • Depth First Search
  • Kahn's Topological Sort

Math

  • Fibonacci Number
  • Is Prime
  • Power Set
  • Prime Factors
  • Sieve of Atkin
  • Sieve of Eratosthenes

String

  • Are Anagrams
  • Are Palindromes
  • Boyer-Moore String Match
  • Boyer-Moore-Horspool String Match
  • Brute Force String Match
  • Damerau-Levenshtein Distance
  • Hamming Distance
  • Has Duplicate Characters
  • Knuth-Morris-Pratt String Match
  • Levenshtein Distance
  • Longest Common Subsequence
  • Longest Common Substring
  • Matching Delimiters
  • Rabin-Karp String Match
  • Sørensen-Dice Coefficient

Usage

To install the algorithms for use in your project run:

yarn add common-algorithms-js

or if you don't have Yarn installed, run:

npm i common-algorithms-js

Once you've downloaded the library, you can start using it in your project like this:

Using require()

var algorithms = require('common-algorithms-js/es5').default

or if you only want a specific algorithm (the Bezier Curve algorithm for example):

var bezierCurve = require('common-algorithms-js/es5').bezierCurve

or if you only want a specific category of algorithms (string algorithms for example):

var stringAlgorithms = require('common-algorithms-js/es5').string

Using ES6 Import/Export

import * as algorithms from 'common-algorithms-js'

or if you only want a specific algorithm (the Fibonacci Number algorithm for example):

import { fibonacciNumber } from 'common-algorithms-js'

or if you only want a specific category of algorithms (math algorithms for example):

import { math } from 'common-algorithms-js'

The default export returns an object that looks something like this:

{
  array: {
    binarySearch: function...,
    bubbleSort: function...,
    ...
  },
  geometry: {
    bezierCurve: function...,
    ...
  },
  graph: {
    breadthFirstSearch: function...,
    ...
  },
  math: {
    fibonacciNumber: function...,
    ...
  },
  string: {
    areAnagrams: function...,
    ...
  },
}

it contains all the algorithms available in the library.

Testing

To run the tests yourself you'll need to download the project and install its node module dependencies via yarn or npm. So, if you haven't already installed Node.js and npm or yarn for use on your command line hop over to the NVM repository to get setup with the Node.js version you'd like to work with. Once you have Node.js and npm installed, clone the project onto your computer using the following command in your terminal/command prompt/console:

git clone https://github.com/sumtype/common-algorithms-js.git

(Just in case you haven't already installed Git, do so by following the installation instructions here, then enter the previous command again once it's installed.) Once you've downloaded the project use the following command to navigate to the project's root directory:

cd common-algorithms-js

Next, install the project's node module dependencies from npm or yarn. Do so by entering this command:

npm i

or this command:

yarn

Once all the dependencies are installed you'll be ready to run the tests. Enter the following command to run them:

npm test

or

yarn test

When running npm test or yarn test all the algorithms, tests, and "./es5.js" file are transpiled based on their corresponding ES6+ files. This way when running your tests not only are your ES6+ algorithms tested in an ES6+ context, but your transpiled ES5 algorithms are tested in transpiled ES5 test contexts. Since modules in tests are loaded via "./es.js" or the transpiled "./es5.js" file the export files themselves are tested too. In addition, standard is run to ensure all ES6+/ES5 code is style compliant and the test breaks if there are issues.

This repository uses Travis-CI for deployment testing on Node.js versions 10.15.x and 11.8.x. Test coverage is reported by Coveralls. Test reports are generated by nyc.

Transpiling ES5 Algorithms

You can also transpile the ES5 versions of tests and algorithms manually. To do so, run:

npm run transpile-es5

or

yarn transpile-es5

About

Common algorithms implemented in JavaScript.

Topics

algorithmsarray-algorithmscommon-algorithmscomputer-sciencecomputer-science-algorithmsgeometry-algorithmsgraph-algorithmsjavascriptjavascript-algorithmsmath-algorithmssorting-algorithmsstring-algorithms

Resources

Readme
MIT license

Code of conduct

Code of conduct

Contributing

Contributing
Activity

Stars

36 stars

Watchers

1 watching

Forks

7 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.