-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathscratch.txt
47 lines (42 loc) · 886 Bytes
/
scratch.txt
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
----- metadata representation experiment
// represents arbitrary metadata as an array
// each entry takes 2 slots in the array: name and value
/** @typedef {any[]} MetaDataArray */
/**
* @param {MetaDataArray} m
* @returns {number}
*/
export function metaCount(m) {
return len(m) / 2;
}
/**
* @param {MetaDataArray} m
* @param {string} key
* @returns {any}
*/
export function metaGet(m, key) {
let n = len(m);
for (let idx = 0; idx < n; idx += 2) {
if (m[idx] === key) {
return m[idx + 1];
}
}
return undefined;
}
/**
* @param {MetaDataArray} m
* @param {number} i
* @returns {string}
*/
export function metaKey(m, i) {
return m[i * 2];
}
/**
* @param {MetaDataArray} m
* @param {number} i
* @returns {string}
*/
export function metaValue(m, i) {
return m[i * 2 + 1];
}
--------------------