mirror of
https://github.com/VickScarlet/lifeRestart.git
synced 2026-04-15 03:23:51 +08:00
增加微信小程序版
This commit is contained in:
31
liferestartWX/utils/liferestart/functions/util.js
Normal file
31
liferestartWX/utils/liferestart/functions/util.js
Normal file
@@ -0,0 +1,31 @@
|
||||
function clone(value) {
|
||||
switch(typeof value) {
|
||||
case 'object':
|
||||
if(Array.isArray(value)) return value.map(v=>clone(v));
|
||||
const newObj = {};
|
||||
for(const key in value) newObj[key] = clone(value[key]);
|
||||
return newObj;
|
||||
default: return value;
|
||||
}
|
||||
}
|
||||
|
||||
function max(...arr) {
|
||||
return Math.max(...arr.flat());
|
||||
}
|
||||
|
||||
function min(...arr) {
|
||||
return Math.min(...arr.flat());
|
||||
}
|
||||
|
||||
function sum(...arr) {
|
||||
let s = 0;
|
||||
arr.flat().forEach(v=>s+=v);
|
||||
return s;
|
||||
}
|
||||
|
||||
function average(...arr) {
|
||||
const s = sum(...arr);
|
||||
return s / arr.flat().length;
|
||||
}
|
||||
|
||||
export { clone, max, min, sum, average };
|
||||
Reference in New Issue
Block a user