@gkucmierz/utils 1.11.0 → 1.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@gkucmierz/utils",
3
- "version": "1.11.0",
3
+ "version": "1.12.1",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@gkucmierz/utils",
9
- "version": "1.11.0",
9
+ "version": "1.12.1",
10
10
  "license": "MIT",
11
11
  "devDependencies": {
12
12
  "husky": "^8.0.1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gkucmierz/utils",
3
- "version": "1.11.0",
3
+ "version": "1.12.1",
4
4
  "description": "Usefull functions for solving programming tasks",
5
5
  "main": "src/main.mjs",
6
6
  "scripts": {
package/src/lcm.mjs ADDED
@@ -0,0 +1,14 @@
1
+
2
+ import {
3
+ gcd,
4
+ gcdBI,
5
+ } from './gcd.mjs';
6
+
7
+ // Least common multiple
8
+
9
+ const getLcm = gcd => {
10
+ return (a, b) => a * b / gcd(a, b);
11
+ }
12
+
13
+ export const lcm = getLcm(gcd);
14
+ export const lcmBI = getLcm(gcdBI);
package/src/phi.mjs CHANGED
@@ -4,6 +4,11 @@ import {
4
4
  gcdBI,
5
5
  } from './gcd.mjs';
6
6
 
7
+ import {
8
+ factors,
9
+ factorsBI,
10
+ } from './factors.mjs';
11
+
7
12
  // Euler's Totient Function
8
13
 
9
14
  const getPhi = (ONE, TWO, gcd) => {
@@ -18,5 +23,16 @@ const getPhi = (ONE, TWO, gcd) => {
18
23
  };
19
24
  }
20
25
 
21
- export const phi = getPhi(1, 2, gcd);
22
- export const phiBI = getPhi(1n, 2n, gcdBI);
26
+ // Eulers formula
27
+
28
+ const getPhiEuler = factors => {
29
+ return n => {
30
+ return [...new Set(factors(n))].reduce((res, f) => res - res / f, n);
31
+ };
32
+ };
33
+
34
+ export const phi = getPhiEuler(factors);
35
+ export const phiBI = getPhiEuler(factorsBI);
36
+
37
+ // export const phi = getPhi(1, 2, gcd);
38
+ // export const phiBI = getPhi(1n, 2n, gcdBI);