@gkucmierz/utils 3.0.0 → 3.0.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.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gkucmierz/utils",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "type": "module",
5
5
  "description": "Usefull functions for solving programming tasks",
6
6
  "keywords": [
@@ -10,7 +10,7 @@ export const binarySearchArr = (arr, target) => {
10
10
  let [a, b] = [0, arr.length];
11
11
  let lm;
12
12
  while (b - a > 0) {
13
- const mid = (a + b) / 2 | 0;
13
+ const mid = Math.trunc((a + b) / 2);
14
14
  const val = arr[mid];
15
15
  if (target < val) {
16
16
  b = mid;
@@ -36,7 +36,7 @@ export const binarySearchLE = (arr, target) => {
36
36
  let [a, b] = [0, arr.length];
37
37
  let lm;
38
38
  while (b - a > 0) {
39
- const mid = (a + b) / 2 | 0;
39
+ const mid = Math.trunc((a + b) / 2);
40
40
  const val = arr[mid];
41
41
  if (target < val) {
42
42
  b = mid;
@@ -60,7 +60,7 @@ export const binarySearchGE = (arr, target) => {
60
60
  let [a, b] = [0, arr.length];
61
61
  let lm;
62
62
  while (b - a > 0) {
63
- const mid = (a + b) / 2 | 0;
63
+ const mid = Math.trunc((a + b) / 2);
64
64
  const val = arr[mid];
65
65
  if (target > val) {
66
66
  a = mid;
@@ -93,7 +93,7 @@ const binarySearchL = (arr, target) => {
93
93
  let [a, b] = [0, arr.length];
94
94
  let lm;
95
95
  while (b - a > 0) {
96
- const mid = (a + b) / 2 | 0;
96
+ const mid = Math.trunc((a + b) / 2);
97
97
  const val = arr[mid];
98
98
  if (target <= val) {
99
99
  b = mid;
@@ -111,7 +111,7 @@ const binarySearchG = (arr, target) => {
111
111
  let [a, b] = [0, arr.length];
112
112
  let lm;
113
113
  while (b - a > 0) {
114
- const mid = (a + b) / 2 | 0;
114
+ const mid = Math.trunc((a + b) / 2);
115
115
  const val = arr[mid];
116
116
  if (target >= val) {
117
117
  a = mid;
package/src/egcd.mjs CHANGED
@@ -12,7 +12,7 @@ export const egcd = (a, b) => {
12
12
  let [x, y] = [0, 1];
13
13
  let [u, v] = [1, 0];
14
14
  while (a !== 0) {
15
- const [q, r] = [b/a | 0, b%a];
15
+ const [q, r] = [Math.trunc(b / a), b % a];
16
16
  const [m, n] = [x - u * q, y - v * q];
17
17
  [b, a, x, y, u, v] = [a, r, u, v, m, n];
18
18
  }
package/src/heap.mjs CHANGED
@@ -18,7 +18,7 @@ export class Heap {
18
18
 
19
19
  #up(idx) {
20
20
  while (idx > 1) {
21
- const ni = idx / 2 | 0;
21
+ const ni = Math.trunc(idx / 2);
22
22
  if (this.#valFn(this.#arr[idx]) < this.#valFn(this.#arr[ni])) {
23
23
  [this.#arr[idx], this.#arr[ni]] = [this.#arr[ni], this.#arr[idx]];
24
24
  }
package/src/pow-mod.mjs CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
  const getPowMod = (ZERO, ONE, TWO, floor) => {
5
5
  return (base, exponent, modulus = null) => {
6
+ if (exponent < ZERO) throw new RangeError('Negative exponent is not supported');
6
7
  if (modulus === null) return base ** exponent;
7
8
  if (modulus === ONE) return ZERO;
8
9
  let result = ONE;