npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

math-functional

v1.0.4

Published

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

Downloads

8

Readme

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