@gkucmierz/utils 1.23.0 → 1.24.0

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/main.mjs CHANGED
@@ -9,8 +9,11 @@ import {
9
9
  bijective2num, bijective2numBI, num2bijective, num2bijectiveBI
10
10
  } from './src/bijective-numeration.mjs'
11
11
  import {
12
- bisectionSearchArr
13
- } from './src/bisection-search.mjs'
12
+ binarySearchArr
13
+ } from './src/binary-search.mjs'
14
+ import {
15
+ copyCase
16
+ } from './src/copy-case.mjs'
14
17
  import {
15
18
  egcd
16
19
  } from './src/egcd.mjs'
@@ -66,7 +69,8 @@ import {
66
69
  export * from './src/SetCnt.mjs';
67
70
  export * from './src/base64.mjs';
68
71
  export * from './src/bijective-numeration.mjs';
69
- export * from './src/bisection-search.mjs';
72
+ export * from './src/binary-search.mjs';
73
+ export * from './src/copy-case.mjs';
70
74
  export * from './src/egcd.mjs';
71
75
  export * from './src/factors.mjs';
72
76
  export * from './src/gcd.mjs';
@@ -86,5 +90,5 @@ export * from './src/square-root.mjs';
86
90
  export * from './src/tonelli-shanks.mjs';
87
91
 
88
92
  export default [
89
- SetCnt, fromBase64, fromBase64Url, toBase64, toBase64Url, bijective2num, bijective2numBI, num2bijective, num2bijectiveBI, bisectionSearchArr, egcd, factors, factorsBI, gcd, gcdBI, getType, gpn, gpnBI, Heap, heronsFormula, heronsFormulaBI, lcm, lcmBI, ListNode, matrixAsArray, memoize, mod, modBI, phi, phiBI, powMod, powModBI, array2range, range2array, squareRoot, squareRootBI, tonelliShanksBI
93
+ SetCnt, fromBase64, fromBase64Url, toBase64, toBase64Url, bijective2num, bijective2numBI, num2bijective, num2bijectiveBI, binarySearchArr, copyCase, egcd, factors, factorsBI, gcd, gcdBI, getType, gpn, gpnBI, Heap, heronsFormula, heronsFormulaBI, lcm, lcmBI, ListNode, matrixAsArray, memoize, mod, modBI, phi, phiBI, powMod, powModBI, array2range, range2array, squareRoot, squareRootBI, tonelliShanksBI
90
94
  ];
package/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@gkucmierz/utils",
3
- "version": "1.23.0",
3
+ "version": "1.24.0",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@gkucmierz/utils",
9
- "version": "1.23.0",
9
+ "version": "1.24.0",
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.23.0",
3
+ "version": "1.24.0",
4
4
  "description": "Usefull functions for solving programming tasks",
5
5
  "main": "main.mjs",
6
6
  "scripts": {
@@ -0,0 +1,15 @@
1
+
2
+ import {
3
+ binarySearchArr,
4
+ } from '../src/binary-search.mjs';
5
+
6
+ describe('binarySearchArr', () => {
7
+ it('few cases', () => {
8
+ expect(binarySearchArr([1, 2, 3, 4], 1)).toBe(0);
9
+ expect(binarySearchArr([1, 2, 3, 4], 2)).toBe(1);
10
+ expect(binarySearchArr([1, 2, 3, 4], 3)).toBe(2);
11
+ expect(binarySearchArr([1, 2, 3, 4], 4)).toBe(3);
12
+ expect(binarySearchArr([1, 2, 3, 4], 0)).toBe(-1);
13
+ expect(binarySearchArr([1, 2, 3, 4], 5)).toBe(-1);
14
+ });
15
+ });
@@ -0,0 +1,12 @@
1
+
2
+ import {
3
+ copyCase,
4
+ } from '../src/copy-case.mjs';
5
+
6
+ describe('copy-case', () => {
7
+ it('few tests', () => {
8
+ expect(copyCase('styczeń', 'january')).toBe('styczeń');
9
+ expect(copyCase('styczeń', 'January')).toBe('Styczeń');
10
+ expect(copyCase('styczeń', 'JANUARY')).toBe('STYCZEŃ');
11
+ });
12
+ });
@@ -1,5 +1,5 @@
1
1
 
2
- export const bisectionSearchArr = (arr, target) => {
2
+ export const binarySearchArr = (arr, target) => {
3
3
  let [a, b] = [0, arr.length];
4
4
  let lm;
5
5
  while (b - a > 0) {
@@ -0,0 +1,12 @@
1
+
2
+
3
+ export const copyCase = (word, from) => {
4
+ const isLower = w => w.toLowerCase() === w;
5
+ const isUpper = w => w.toUpperCase() === w;
6
+ if (isLower(from)) return word.toLowerCase();
7
+ if (isUpper(from)) return word.toUpperCase();
8
+ if (isUpper(from[0]) && isLower(from.slice(1))) {
9
+ return word[0].toUpperCase() + word.slice(1).toLowerCase();
10
+ }
11
+ return word;
12
+ };
package/src/matrix.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- // represent matrix using array using Proxy
3
+ // represent matrix as array using Proxy
4
4
  // todo: iterator can be added
5
5
 
6
6
  export const matrixAsArray = matrix => {
@@ -1,15 +0,0 @@
1
-
2
- import {
3
- bisectionSearchArr,
4
- } from '../src/bisection-search.mjs';
5
-
6
- describe('bisectionSearchArr', () => {
7
- it('few cases', () => {
8
- expect(bisectionSearchArr([1, 2, 3, 4], 1)).toBe(0);
9
- expect(bisectionSearchArr([1, 2, 3, 4], 2)).toBe(1);
10
- expect(bisectionSearchArr([1, 2, 3, 4], 3)).toBe(2);
11
- expect(bisectionSearchArr([1, 2, 3, 4], 4)).toBe(3);
12
- expect(bisectionSearchArr([1, 2, 3, 4], 0)).toBe(-1);
13
- expect(bisectionSearchArr([1, 2, 3, 4], 5)).toBe(-1);
14
- });
15
- });