-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoJSON.js
More file actions
58 lines (52 loc) · 1.55 KB
/
toJSON.js
File metadata and controls
58 lines (52 loc) · 1.55 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
51
52
53
54
55
56
57
58
// toJSON.stringify
RegExp.prototype.toJSON = function () {
return this.toString();
};
Date.prototype.toJSON = function () {
return {
year: this.getFullYear(),
monthIndex: this.getMonth(),
date: this.getDate(),
day: this.getDay(),
H: this.getHours(),
i: this.getMinutes(),
s: this.getSeconds(),
ms: this.getMilliseconds(),
tz: this.getTimezoneOffset(),
utc: this.toISOString(),
this: this.toString(),
};
};
BigInt.prototype.toJSON = function () {
return `${this}n`;
};
const date = new Date();
const http = JSON.stringify([5n,date], null, 2);
//pre.innerText = http;console.log(JSON.parse(http));
function processArray(arr) {
const array2 = [];
for (const value of arr) {
try {
// Try converting the value to BigInt
const bigIntValue = BigInt(value);
array2.push(bigIntValue);
} catch {
// If BigInt conversion fails, try converting to Number
const numberValue = Number(value);
if (!Number.isNaN(numberValue)) {
array2.push(numberValue);
}
}
}
return array2;
}
function customMax(arr) {
const validValues = processArray(arr);
if (validValues.length === 0) return NaN;
return validValues.reduce((max, val) => (val > max ? val : max));
}
function customMin(arr) {
const validValues = processArray(arr);
if (validValues.length === 0) return NaN;
return validValues.reduce((min, val) => (val < min ? val : min));
}