Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | 11x 9x 8x 8x 4x 4x 2x 2x 2x 2x 2x 2x 3x 4x 8x 2x 6x 2x 4x 1x 1x 1x 1x 1x 1x | // export function clone(source) {
// if (source === undefined) return undefined; // 返回 undefined
// if (source === null) return null; // 返回 null
// const t = type(source);
// if (t !== 'object' && t !== 'array') {
// return source;
// }
// let target;
// if (t === 'object') {
// target = {};
// for (let i in source) {
// if (source.hasOwnProperty(i)) {
// target[i] = clone(source[i]);
// }
// }
// } else {
// target = [];
// for (let i = 0; i < source.length; i++) {
// target[i] = clone(source[i]);
// }
// return target;
// }
// }
export function clone(source) {
if (source === undefined) return undefined; // 返回 undefined
if (source === null) return null; // 返回 null
const t = type(source);
if (t !== 'object' && t !== 'array') {
return source;
}
let target;
if (t === 'object') {
target = {};
for (let i in source) {
Eif (source.hasOwnProperty(i)) {
target[i] = clone(source[i]);
}
}
} else { // When t is 'array'
target = [];
for (let i = 0; i < source.length; i++) {
target[i] = clone(source[i]);
}
}
return target; // Return the cloned object or array here
}
export function type(val) {
if (Array.isArray(val)) {
return 'array';
} else if (val !== null && typeof val === 'object') {
return 'object';
} else {
return typeof val;
}
}
export function getUrlParam(key) {
const query = location.search[0] === '?' ? location.search.slice(1) : location.search;
const map = query.split("&").reduce((acc, data) => {
const arr = data.split("=");
acc[arr[0]] = arr[1];
return acc;
}, {});
return map[key];
}
// function clone(source) {
// // 處理邊界條件
// if (source === undefined) return undefined; // 返回 undefined
// if (source === null) return null; // 返回 null
// const t = type(source);
// if (t !== 'object' && t !== 'array') {
// return source;
// }
// let target;
// if (t === 'object') {
// target = {};
// for (let i in source) {
// if (source.hasOwnProperty(i)) {
// target[i] = clone(source[i]);
// }
// }
// } else {
// target = [];
// for (let i = 0; i < source.length; i++) {
// target[i] = clone(source[i]);
// }
// }
// return target;
// }
// function type(val) {
// if (Array.isArray(val)) {
// return 'array';
// } else if (val !== null && typeof val === 'object') {
// return 'object';
// } else {
// return typeof val;
// }
// }
// function getUrlParam(key) {
// const query = location.search[0] === '?' ? location.search.slice(1) : location.search;
// const map = query.split("&").reduce((acc, data) => {
// const arr = data.split("=");
// acc[arr[0]] = arr[1];
// return acc;
// }, {});
// return map[key];
// }
// // 使用 module.exports 來導出函數
// module.exports = { clone, type, getUrlParam };
|