Giter VIP home page Giter VIP logo

math's Introduction

Math functional Build Status Coverage Status Maintainability

Just a project to abstract math functions from basic to I-don't-know-where.

Usage

Basic

Operations

add()
Receives
add(x, y)

Where x and y are numbers

Returns

A number corresponding to the answer

Examples
add(1,2)
// 3
add(8,-2)
// 6
sum()
Receives
sum(...addends)

Where addends is a numeric array of any size

Returns

A number corresponding to the sum of all addends

Examples
sum(1,2,3,4)
// 10
sum(1, -8, 10, 15, -17)
// 1
sub()
Receives
sub(x, y)

Where x and y are numbers

Returns

A number corresponding to the answer

Examples
sub(1,2)
// -1
sub(-8,-2)
// -6
diff()
Receives
diff(...parts)

Where parts is a numeric array of any size

Returns

A number corresponding to the difference of all parts, from left to right

Examples
diff(1,2,3,4)
// -8
diff(1, -8, 10, 15, -17)
// 1
multiply()
Receives
multiply(x, y)

Where x and y are numbers

Returns

A number corresponding to the answer

Examples
multiply(1,2)
// 2
multiply(2,-2)
// 4
product()
Receives
product(...parts)

Where parts is a numeric array of any size

Returns

A number corresponding to the multiplication of all parts

Examples
product(1,2,3,4)
// 24
product(1, -8, 10, 15, -17)
// 20400
divide()
Receives
divide(x, y)

Where x and y are numbers

Returns

A number corresponding to the answer

Examples
divide(4,2)
// 2
divide(15,3)
// 5
quotient()
Receives
quotient(...parts)

Where parts is a numeric array of any size

Returns

A number corresponding to the division of all parts, from left to right

Examples
quotient(1,2,3,4)
// 0,041666667
quotient(1, -8, 10, 15, -17)
// 0,00004902

Parity

isOdd()
Receives
isOdd(x)

Where x is a number

Returns

Boolean value indicating that number is odd or not

Examples
isOdd(5)
// true
isOdd(2)
// false
isEven()
Receives
isEven(x)

Where x is a number

Returns

Boolean value indicating that number as Even or not

Examples
isEven(5)
// false
isEven(2)
// true

Algebra

Primality

getRelevantPossibleDivisors()
Receives
getRelevantPossibleDivisors(x)

Where x is a number

Returns

An array of every relevant divisors, for prime calculation, for x. In other words, it will return an array of integers from 2 until โˆšx

Examples
getRelevantPossibleDivisors(9)
// [2,3]
getRelevantPossibleDivisors(8)
// [2]
isPrime()
Receives
isPrime(x)

Where x is a number

Returns

Boolean indicator about x primality

Examples
isPrime(7)
// true
isPrime(9)
// false

Utils

bulkFunction()
Receives
bulkFunction(list, fn, initialValue)

Where list is an array, fn a function, and initialValue a mixed type

Returns

Return the result of a reduce method applied to your list with your function. Using initialValue to begin reducing.

Examples
bulkFunction([1,2], (acc, item) => acc + item, 0)
// 3
getRandomPositiveNumber()
getRandomPositiveNumber(limit)

Where limit is an integer. Default value for limit is 10.

Returns

Return a random number with max value set as parameter.

Examples
getRandomPositiveNumber()
getRandomNegativeNumber()
getRandomNegativeNumber(limit)

Where limit is an integer. Default value for limit is -10.

Returns

Return a random number with max value set as parameter.

Examples
getRandomNegativeNumber()
getRandomPositiveArray()
getRandomPositiveArray(limit, size)

Where limit and size are integers. Default value for limit is 10, and for size is 4.

Returns

Return an array, with required size, where every content item is a positive number lower than limit.

Examples
getRandomPositiveArray()
getRandomNegativeArray()
getRandomNegativeArray(limit, size)

Where limit and size are integers. Default value for limit is -10, and for size is 4.

Returns

Return an array, with required size, where every content item is a negative number lower than limit.

Examples
getRandomNegativeArray()
getRandomMixedArray()
getRandomMixedArray(limit, size)

Where limit and size are integers. Default value for limit is -10/10, and for size is 4.

Returns

Return an array, with required size, where every content item is an any signal number lower than limit.

Examples
getRandomMixedArray()
generateIntegerArray()
generateIntegerArray(initialValue, finalValue)

Where initialValue and finalValue are integers. Default value for initialValue is 0, and for finalValue is 1.

Returns

Return an array of integers, beggining on initialValue and finishing on finalValue

Examples
generateIntegerArray()
// [0-1]
generateIntegerArray(5,9)
// [5,6,7,8,9]

Test

npm test

To check tests coverage

npm run coverage-text

math's People

Watchers

Renie Siqueira avatar James Cloos avatar  avatar

math's Issues

Primality Check

Include a function to check whether a number is prime or not.

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.