nv-random-util 0.0.2 → 0.0.3

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.
Files changed (2) hide show
  1. package/index.js +24 -1
  2. package/package.json +2 -3
package/index.js CHANGED
@@ -7,6 +7,29 @@ function rand_from_ary(ary) {
7
7
  }
8
8
 
9
9
 
10
+ function rand_idxes(...args) {
11
+ let idxary;
12
+ if(Array.isArray(args[0])) {
13
+ idxary = args[0];
14
+ idxary.sort((a,b)=>a-b);
15
+ } else {
16
+ let si = args[0];
17
+ let ei = args[1];
18
+ if(si>ei) {tmp = si; si =ei; ei=tmp}
19
+ idxary = [];
20
+ for(let i=si;i<ei;++i) {
21
+ idxary.push(i)
22
+ }
23
+ }
24
+ let rslt = [];
25
+ for(let idx of idxary) {
26
+ if(Math.random()>=0.5) {
27
+ rslt.push(idx)
28
+ }
29
+ }
30
+ return rslt;
31
+ }
32
+
10
33
  function rand_from_set(st) {
11
34
  return(rand_from_ary(Array.from(st)))
12
35
  }
@@ -46,7 +69,7 @@ function rand_value_from_map(mp) {
46
69
  }
47
70
 
48
71
  module.exports = {
49
- rand_from_ary,
72
+ rand_from_ary,rand_idxes,
50
73
  rand_from_set,
51
74
  rand_key_from_dict,
52
75
  rand_value_from_dict,
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "dependencies": {
3
- "nv-random-number": "^1.0.2"
3
+ "nv-random-number": "^1.0.3"
4
4
  },
5
- "version": "0.0.2",
5
+ "version": "0.0.3",
6
6
  "name": "nv-random-util",
7
7
  "description": "nv-random-util ============ - nv-random-util",
8
8
  "main": "index.js",
9
- "devDependencies": {},
10
9
  "scripts": {
11
10
  "test": "echo \"Error: no test specified\" && exit 1"
12
11
  },