Coder Social home page Coder Social logo

mathjs's Introduction

MathJs


MathJs is a small javascript library for performing mundane tasks repeatedly in a easy way. A few of the things that this library is capable of are operations like, rounding a decimal upto 2 decimal places, or trying to find the difference between two arrays.

Read on to find out more features about this library.

Download

You can download this library as an npm module by running the following command

npm install simplemathjs

Once downloaded, you can include in your html file like so

<script type="text/javascript" src="node_modules/dist/math.min.js"></script>

That's it, you can now use this library by referring to the MJ variable within your javascript

MJ.round(3.14159265, 2)
// 3.14

MJ.arrayDiff([1, 2, 3, 4], [1, 4, 2])
// [3]

There functionalities are segrated by primarily three sections

  1. Array Functionalities
  2. Numeric Functionalities
  3. String Functionalities

Array Functionalities

List of Functions that you can operate on Arrays

arrayFlatten

Given an array of arrays, it will flatten hierarchies of arrays and return a single array.

MJ.arrayFlatten([1, 2, [3, 4, [5, 6], [7]], [8, 9]])
// [1, 2, 3, 4, 5, 6, 7, 8, 9]

arrayUnique

Given a list of items in an array, it will returns an array of elements containing all the elements occurring only once, i.e. removes duplicates.

MJ.arrayUnique([1, 1, 'b', false, false, true, 'b', undefined, undefined])
// [1, "b", false, true, undefined]

arrayIntersection

Given two sets of arrays, returns the set of unique elements which are present in both

MJ.arrayIntersection([1, 2, 3, 2], [1, 5, 2, 1])
// [1, 2]

arrayDiff

Given two set of arrays, returns the set of elements present in the left, but not in the right.

MJ.arrayDiff([1, 2, 3, 4], [1, 4, 2])
// [3]

arrayUnion

Given a set of arrays as arguments, returns a single array containing all the elements present in every argument, including duplicates.

NOTE: the arguments for the function always need to be an array

MJ.arrayUnion([1], [], [2])
// [1, 2]

arrayMean

Given an array of numbers, computes the mean and returns it.

MJ.arrayMean([1, 2, 3, 100, 101, 202])
// 68.16666666666667

Numeric Functionalities

List of Functions that you can operate on Numbers

round

Given a long type number, you can round it off to how many ever decimal places you want to

MJ.round(3.14159265, 3)
// 3.141

factorial

Returns the factorial for a number

MJ.factorial(5)
// 120

factors

Get the prime factors for a number

MJ.factors(10)
// [1, 10, 2, 5]

isPrime

Checks whether a given number is prime or not

MJ.isPrime(5)
// true

remainder

Returns the remainder when a numerator is divided by a denominator

MJ.remainder(10, 4)
// 2

power

Returns the exponent value of a number.

MJ.power(2, 5)
// 32

// you can also directly get the `square` or the `cube`
MJ.square(2)
// 4

MJ.cube(2)
// 8

String Functionalities

List of Functions that you can operate on Strings

titleCase

Convert a string to titlecase.

MJ.titleCase(' abC dEf')
// Abc Def

mathjs's People

Contributors

kaizer1v avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mathjs's Issues

Support ES6 and TypeScript

I think ES6 and TypeScript is a gateway to great javascript. Depending on the use case Babel or official Typescript transpiler can be used.

Provide Documentation

  • API - Provide all methods/functions exposed
  • Examples - Give examples for each functionality

Test cases

Write test cases for every method in MJ.

Build

Have a build system in place which

  • minifies files
  • unit test cases
  • install-able via bower, npm using githublink

Method chaining

Should be allowed to call like

MJ.arrayDiff(['a', 'b', 'c'], ['b']).arrayUnion(['z', 'x'])

and return an MJ object

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.