@gkucmierz/utils 1.10.0 → 1.10.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.10.0",
3
+ "version": "1.10.1",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@gkucmierz/utils",
9
- "version": "1.10.0",
9
+ "version": "1.10.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.10.0",
3
+ "version": "1.10.1",
4
4
  "description": "Usefull functions for solving programming tasks",
5
5
  "main": "src/main.mjs",
6
6
  "scripts": {
package/spec/mod.spec.mjs CHANGED
@@ -9,6 +9,8 @@ describe('mod', () => {
9
9
  expect(mod(4, 100)).toEqual(4);
10
10
  expect(mod(104, 100)).toEqual(4);
11
11
  expect(mod(4 - 100, 100)).toEqual(4);
12
+ expect(mod(4 + 96, 100)).toEqual(0);
13
+ expect(mod(-4 - 96, 100)).toEqual(0);
12
14
  });
13
15
 
14
16
  it('mod sign', () => {
@@ -24,6 +26,8 @@ describe('mod BI', () => {
24
26
  expect(modBI(4n, 100n)).toEqual(4n);
25
27
  expect(modBI(104n, 100n)).toEqual(4n);
26
28
  expect(modBI(4n - 100n, 100n)).toEqual(4n);
29
+ expect(modBI(4n + 96n, 100n)).toEqual(0n);
30
+ expect(modBI(-4n - 96n, 100n)).toEqual(0n);
27
31
  });
28
32
 
29
33
  it('mod sign', () => {
package/src/mod.mjs CHANGED
@@ -4,7 +4,8 @@
4
4
  const getMod = ZERO => {
5
5
  return (dividend, divisor) => {
6
6
  if ((dividend < ZERO) ^ (divisor < ZERO)) {
7
- return divisor - (-dividend % divisor);
7
+ const res = -dividend % divisor;
8
+ return res === ZERO ? ZERO : divisor - res;
8
9
  }
9
10
  return dividend % divisor;
10
11
  };