-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidateArrays.js
More file actions
28 lines (23 loc) · 778 Bytes
/
validateArrays.js
File metadata and controls
28 lines (23 loc) · 778 Bytes
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
function validateArrays(arr, num) {
try {
if (!arr && !num) throw new ReferenceError("Send the parameters!");
if (typeof arr !== "object")
throw new TypeError("Send a element of type Array!");
if (typeof num !== "number")
throw new TypeError("Send a element of type Numberdo!");
if (arr.length !== num) throw new RangeError("Size of array invalid!");
return arr;
} catch (e) {
if (e instanceof RangeError) {
console.log("RangeError!");
console.log(e.stack);
} else if (e instanceof ReferenceError) {
console.log("ReferenceError!");
console.log(e.stack);
} else {
console.log("Another error type!");
console.log(e.stack);
}
}
}
console.log("Arrays: " + validateArrays([1, 2, 3], 3));