Skip to content

Commit 0109ac1

Browse files
committed
exporting files
1 parent 3d78049 commit 0109ac1

10 files changed

Lines changed: 177 additions & 126 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Mathematica
2+
3+
A npm package which will help you if you fear math.

TODO.md

Lines changed: 0 additions & 33 deletions
This file was deleted.

index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// export * from "./lib/basic";
2+
// export * from "./lib/conversion";
3+
// export * from "./lib/isMethod";
4+
// export * from "./lib/number";
5+
// export * from "./lib/search";
6+
// export * from "./lib/sort";
7+
8+
const basic = require("./lib/basic");
9+
const conversion = require("./lib/conversion");
10+
const ismethod = require("./lib/isMethod");
11+
const number = require("./lib/number");
12+
const search = require("./lib/search");
13+
const sort = require("./lib/sort");
14+
15+
module.exports = {
16+
basic,
17+
conversion,
18+
ismethod,
19+
number,
20+
search,
21+
sort,
22+
};

lib/basic.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,51 @@
33
* elements, return the result
44
* @param {*} array
55
*/
6-
export function addition(...array) {
6+
const addition = (...array) => {
77
if (array[0][0] !== undefined) array = array[0];
88
return array.reduce((a, b) => a + b);
9-
}
9+
};
1010

1111
/**
1212
* Pass an (array or argument) and subtract all the
1313
* elements, return the result
1414
* @param {*} array
1515
*/
16-
export function subtraction(...array) {
16+
const subtraction = (...array) => {
1717
if (array[0][0] !== undefined) array = array[0];
1818
return array.reduce((a, b) => a - b);
19-
}
19+
};
2020

2121
/**
2222
* Pass an (array or argument) and multiplication all the
2323
* elements, return the result
2424
* @param {*} array
2525
*/
26-
export function multiplication(...array) {
26+
const multiplication = (...array) => {
2727
if (array[0][0] !== undefined) array = array[0];
2828
return array.reduce((a, b) => a * b);
29-
}
29+
};
3030

3131
/**
3232
* Pass an (array or argument) and divide all the
3333
* elements, return the result
3434
* @param {*} array
3535
*/
36-
export function division(...array) {
36+
const division = (...array) => {
3737
if (array[0][0] !== undefined) array = array[0];
3838
return array.reduce((a, b) => a / b);
39-
}
39+
};
4040

4141
/**
4242
* Pass an (array or argument)
4343
* return average of the numbers
4444
* @param {*} array
4545
*/
46-
export function average(...array) {
46+
const average = (...array) => {
4747
if (array[0][0] !== undefined) array = array[0];
4848
let sum = array.reduce((a, b) => a + b);
4949
return parseFloat(sum / array.length);
50-
}
50+
};
5151

5252
/**
5353
* Calculate the mod of collection index
@@ -57,26 +57,37 @@ export function average(...array) {
5757
* getRemainder(3, 5); // 3
5858
* getRemainder(6, 5); // 1
5959
*/
60-
export function getRemainder(firstNumber, secondNumber) {
60+
const getRemainder = (firstNumber, secondNumber) => {
6161
return ((firstNumber % secondNumber) + secondNumber) % secondNumber;
62-
}
62+
};
6363

6464
/**
6565
* pass arguments or array and get the minimum number
6666
* getMinimum([1,3,5,4,9]) // 1
6767
* getMinimum(2,45,2,76,0,4) // 0
6868
* @param {...any} array
6969
*/
70-
export function getMinimum(...array) {
70+
const getMinimum = (...array) => {
7171
if (array[0][0] !== undefined) array = array[0];
7272
return Math.min(...array);
73-
}
73+
};
7474

7575
/**
7676
* pass arguments or array and get the maximum number
7777
* @param {...any} array
7878
*/
79-
export function getMaximum(...array) {
79+
const getMaximum = (...array) => {
8080
if (array[0][0] !== undefined) array = array[0];
8181
return Math.max(...array);
82-
}
82+
};
83+
84+
module.exports = {
85+
addition,
86+
subtraction,
87+
multiplication,
88+
division,
89+
average,
90+
getRemainder,
91+
getMaximum,
92+
getMinimum,
93+
};

lib/conversion.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,45 @@
33
* @param {*} number
44
* digitToArray(12345); // [1, 2, 3, 4, 5]
55
*/
6-
export function digitToArray(number) {
6+
const digitToArray = (number) => {
77
return `${number}`.split("").map((v) => parseInt(v));
8-
}
8+
};
99

1010
/**
1111
* Convert a number to equivalent characters
1212
* @param {*} number
1313
* numberToChars(0); // A
1414
* numberToChars(51); // AZ
1515
*/
16-
export function numberToChars(number) {
16+
const numberToChars = (number) => {
1717
return `${number >= 26 ? toChars(Math.floor(number / 26) - 1) : ""}
1818
${"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[number % 26]}`;
19-
}
19+
};
2020

2121
/**
2222
* Convert degrees to radians
2323
* @param {*} deg
2424
*/
25-
export function degsToRads(deg) {
25+
const degsToRads = (deg) => {
2626
return (deg * Math.PI) / 180.0;
27-
}
27+
};
2828

2929
/**
3030
* Convert radians to degrees
3131
* @param {*} rad
3232
*/
33-
export function radsToDegs(rad) {
33+
const radsToDegs = (rad) => {
3434
return (rad * 180) / Math.PI;
35-
}
35+
};
3636

3737
/**
3838
* Given a string and convert it to a number
3939
* @param {*} str
4040
* console.log(stringToNumber("25"));
4141
*/
42-
export function stringToNumber(str) {
42+
const stringToNumber = (str) => {
4343
return parseFloat(str);
44-
}
44+
};
4545

4646
/**
4747
* Pass the number in string format and then give fromBase and toBase
@@ -55,12 +55,21 @@ export function stringToNumber(str) {
5555
* @param {*} fromBase
5656
* @param {*} toBase
5757
*/
58-
function convertNumber(n, fromBase, toBase) {
58+
const convertNumber = (n, fromBase, toBase) => {
5959
if (fromBase === void 0) {
6060
fromBase = 10;
6161
}
6262
if (toBase === void 0) {
6363
toBase = 10;
6464
}
6565
return parseInt(n.toString(), fromBase).toString(toBase);
66-
}
66+
};
67+
68+
module.exports = {
69+
digitToArray,
70+
numberToChars,
71+
radsToDegs,
72+
degsToRads,
73+
stringToNumber,
74+
convertNumber,
75+
};

lib/isMethod.js

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,46 @@
44
* @param {*} dividend
55
* @param {*} divisor
66
*/
7-
export function isDivisor(dividend, divisor) {
7+
const isDivisor = (dividend, divisor) => {
88
return dividend % divisor == 0;
9-
}
9+
};
1010

1111
/**
1212
* Pass a number and return true or false
1313
* based on if the number is even
1414
* @param {*} number
1515
*/
16-
export function isEven(number) {
16+
const isEven = (number) => {
1717
return number % 2 == 0;
18-
}
18+
};
1919

2020
/**
2121
* Pass a number and return true or false
2222
* based on if the number is odd
2323
* @param {*} number
2424
*/
25-
export function isOdd(number) {
25+
const isOdd = (number) => {
2626
return number % 2 != 0;
27-
}
27+
};
2828

2929
/**
3030
* Pass a number and return true or false
3131
* if the number is prime or not
3232
* @param {*} num
3333
*/
34-
export function isPrime(num) {
34+
const isPrime = (num) => {
3535
for (let i = 2, s = Math.sqrt(num); i <= s; i++)
3636
if (num % i === 0) return false;
3737
return num > 1;
38-
}
38+
};
3939

4040
/**
4141
* Check palindrome number
4242
* @param {*} number
4343
* palindromeNumber(45674); // false
4444
* palindromeNumber(4567654); // true
4545
*/
46-
47-
export function isPalindrome(number) {
46+
const isPalindrome = (number) => {
4847
var final = 0,
4948
temp = number;
5049
while (number > 0) {
@@ -53,37 +52,48 @@ export function isPalindrome(number) {
5352
final = final * 10 + rem;
5453
}
5554
return final == temp;
56-
}
55+
};
5756

5857
/**
5958
* Check positive number
6059
* @param {*} number
6160
* isPositive(45674); // true
6261
* isPositive(-4567654); // false
6362
*/
64-
export function isPositive(number) {
63+
const isPositive = (number) => {
6564
if (number === 0) return false;
6665
return ((number >> 31) & 1) === 0;
67-
}
66+
};
6867

6968
/**
7069
* Check negative number
7170
* @param {*} number
7271
* isNegative(45674); // false
7372
* isNegative(-4567654); // true
7473
*/
75-
export function isNegative(number) {
74+
const isNegative = (number) => {
7675
if (number === 0) return false;
7776
return ((number >> 31) & 1) === 1;
78-
}
77+
};
7978

8079
/**
8180
* Check isPowerOfTwo number
8281
* @param {*} number
8382
* isPowerOfTwo(35); // false
8483
* isPowerOfTwo(32); // true
8584
*/
86-
export function isPowerOfTwo(number) {
85+
const isPowerOfTwo = (number) => {
8786
if (number < 1) return false;
8887
return (number & (number - 1)) === 0;
89-
}
88+
};
89+
90+
module.exports = {
91+
isDivisor,
92+
isEven,
93+
isOdd,
94+
isPrime,
95+
isPalindrome,
96+
isPositive,
97+
isNegative,
98+
isPowerOfTwo,
99+
};

0 commit comments

Comments
 (0)