MathN library, Things about math probably
install MathN
with npm:
npm install mathn
<script src="//unpkg.com/mathn@1.1.8/mathn-web-min.js"></script>
Download the latest MathN for browser
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 ]
returns a sequence of numbers
range(start, stop, step) // step default value is 1
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