-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathavenLib.js
More file actions
50 lines (50 loc) · 1.12 KB
/
avenLib.js
File metadata and controls
50 lines (50 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: red; icon-glyph: eye-slash;
//backend utils to make life easier
const VERSION="1.3.1"
function shuffle(l){
let out = [...l]
for (let i = 1; i < out.length; i++) {
let j = (0 | Math.random() * (i + 1))
let t = out[i]
out[i] = out[j]
out[j] = t
}
return out
}
function randint(n){
return Math.floor(Math.random()*n)
}
function readFile(path,separator,handler=FileManager.iCloud()){
data=handler.readString(path)
if (separator){
return data.split(separator)
}
return data
}
function count(in){
let li={}
let cl=in
let cvs=cl.split(",")
for (const entry of cvs){
li[entry]="0"
}
for (const entry of cvs){
let aaaa = parseInt(li[entry])+1
let bbbb = aaaa.toString()
li[entry]=aaaa
}
var out="Sample size: "+cvs.length
let ab=Object.keys(li)
for (let c=0;c<ab.length;c++){
let e=ab[c]
if (!(li[e]=="0")){
let aa=((c==0)? "\n":"\n")
let ef=aa+e+": "+li[e]
out+=ef
}
}
return out
}
module.exports={shuffle,randint,readFile,count,VERSION}