Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

array-math

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-math - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

test/testFactorial.js

15

index.js

@@ -43,3 +43,3 @@ function factors(n) {

function range(low, high) {
if (!low) {
if (typeof low === 'undefined') {
low = 0

@@ -62,9 +62,15 @@ high = 0

function multiply(a) {
return a.reduce(function (memo, curr) { return memo*curr }, 1)
return a.reduce(function(memo, curr) { return memo*curr }, 1)
}
function sum(a) {
return a.reduce(function (memo, curr) { return memo+curr }, 0)
return a.reduce(function(memo, curr) { return memo+curr }, 0)
}
function factorial(high, low) {
if (typeof low === 'undefined') low = 0
if (typeof high === 'undefined') high = 0
return multiply( range(low, high+1).filter(function(e) { return (e!==0) }) )
}
module.exports = {

@@ -76,3 +82,4 @@ factors: factors,

multiply: multiply,
sum: sum
sum: sum,
factorial: factorial
}
{
"name": "array-math",
"version": "0.0.5",
"version": "0.0.6",
"main": "./index.js",

@@ -9,12 +9,13 @@ "author": {

},
"description": "Do math on arrays: find divisors or factors of a number, sum or multiply an array, and more!",
"description": "Do math on arrays: find divisors or factors of a number, sum or multiply an array, and much more!",
"keywords": [
"math",
"array",
"factor",
"factor",
"divisor",
"prime",
"range",
"sum",
"multiply"
"prime",
"range",
"sum",
"multiply",
"factorial",
"largest",
"smallest"
],

@@ -21,0 +22,0 @@ "repository": {

@@ -12,5 +12,6 @@ array-math

- [aMath.isPrime(n)](https://github.com/ArtskydJ/array-math#amathisprimen)
- [aMath.range(n[, m])](https://github.com/ArtskydJ/array-math#amathrangenm)
- [aMath.range(n[, m])](https://github.com/ArtskydJ/array-math#amathrangen-m)
- [aMath.multiply(a)](https://github.com/ArtskydJ/array-math#amathmultiplya)
- [aMath.sum(a)](https://github.com/ArtskydJ/array-math#amathsuma)
- [aMath.factorial(h[, l])](https://github.com/ArtskydJ/array-math#amathfactorialh-l)
- [Example](https://github.com/ArtskydJ/array-math#example)

@@ -58,5 +59,9 @@ - [License](https://github.com/ArtskydJ/array-math#license)

n is a number. If the m parameter was passed in, then n is the low number and m is the high number. If the m parameter was not passed in, then n is the high number. (See examples below.)
aMath.range(0) // -> []
aMath.range(1) // -> [1]
aMath.range(1) // -> [0]
aMath.range(2) // -> [0, 1]
aMath.range(2, 2) // -> []
aMath.range(2, 3) // -> [2]
aMath.range(3) // -> [0, 1, 2]

@@ -84,4 +89,25 @@ aMath.range(10) // -> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

##aMath.factorial(h[, l])
h is a number. It is the high number. It defaults to 0.
l is a number. It is the low number. It defaults to 0.
While multiplying, it will never multiply by 0.
aMath.factorial() // -> 1
aMath.factorial(0) // -> 1
aMath.factorial(1) // -> 1
aMath.factorial(2) // -> 2 (2x1)
aMath.factorial(3) // -> 6 (3x2x1)
aMath.factorial(5) // -> 120 (5x4x3x2x1)
aMath.factorial(5, 0) // -> 120 (5x4x3x2x1)
aMath.factorial(5, 1) // -> 120 (5x4x3x2x1)
aMath.factorial(5, 2) // -> 120 (5x4x3x2)
aMath.factorial(5, 3) // -> 60 (5x4x3)
aMath.factorial(5, 4) // -> 20 (5x4)
aMath.factorial(10) // -> 3628800 (10x9x8x7x6x5x4x3x2x1)
aMath.factorial(10, 3) // -> 1814400 (10x9x8x7x6x5x4x3)
aMath.factorial(10, 5) // -> 151200 (10x9x8x7x6x5)
##License
[MIT](http://opensource.org/licenses/MIT)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc