mathn

1.1.8 • Public • Published

MathN

MathN library, Things about math probably

Installation

NPM

install MathN with npm:

npm install mathn

CDN

<script src="//unpkg.com/mathn@1.1.8/mathn-web-min.js"></script>

Download

Download the latest MathN for browser

Examples

const mathn = require('mathn');

// Return random integer in range (min max)
console.log(mathn.randint(1, 100)); // 78

// Returns random element from a non-empty sequence
console.log(mathn.choice(['Sleep', 'Workout', 'Shop'])); // Sleep

// Returns sum of an array
console.log(mathn.sum([10, 70, 20])); // 100

// Return the next random number in the range (0.0 to 1.0)
console.log(mathn.random()); // 0.8410564055965708

// Calculate your expression if possible
console.log(mathn.calculate('(14 + 1) * 2')) // 30

// Shuffle an array
console.log(mathn.shuffle(['A', 'B', 'a', 'b', '1', '2'])); // [ 'A', 'a', '1', 'B', '2', 'b' ]
console.log(mathn.shuffle(['A', 'B', 'a', 'b', '1', '2']).join('')); // A21Bab

// Also you can spicify a length for it
console.log(math.shuffle([1, 2, 3, 4, 5, 6, 7, 8, 9, 0], 5)) // [ 5, 1, 6, 7, 0 ]

range() Function

returns a sequence of numbers

Syntax

range(start, stop, step) // step default value is 1

Examples

var list = mathn.range(0, 10) // [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]

Loop throw it

for(i in mathn.range(1, 10)) {
  console.log(i)
}

Output:

0
1
2
3
4
5
6
7
8
9

Dependents (0)

Package Sidebar

Install

npm i mathn

Weekly Downloads

0

Version

1.1.8

License

ISC

Unpacked Size

5.68 kB

Total Files

6

Last publish

Collaborators

  • nawafalqari