This repository has been archived by the owner on Sep 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
any_missing.hhs
57 lines (48 loc) · 1.61 KB
/
any_missing.hhs
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
51
52
53
54
55
56
57
/**
* @author Jianan Lin (林家南)
* @param input - an array, matrix, tensor that you want to determine missing
* @returns - true if missing, false else
* A missing element is NaN, null, '', or undefined. Notice [] and {} are not missing.
*
*/
function any_missing(input) {
*import math: ndim
*import math: deep_copy
// argument check
if (arguments.length === 0) {
throw new Error('Exception occurred in any_missing - no argument given');
}
if (arguments.length > 1) {
throw new Error('Exception occurred in any_missing - wrong argument number');
}
if (!(Array.isArray(input)) && !(input instanceof Mat) && !(input instanceof Tensor)) {
throw new Error('Exception occurred in any_missing - input must be an array, matrix or tensor');
}
let in_type = input instanceof Mat || input instanceof Tensor;
let raw_in = in_type ? input.clone().val : deep_copy(input);
return anymissing_helper(raw_in);
function anymissing_helper(raw_in) {
if (ndim(raw_in) === 1) {
for (let i = 0; i < raw_in.length; i++) {
if (raw_in[i] || raw_in[i] === 0) {
continue;
}
else {
return true;
}
}
return false;
}
else {
for (let i = 0; i < raw_in.length; i++) {
if (anymissing_helper(raw_in[i]) === false) {
continue;
}
else {
return true;
}
}
return false;
}
}
}