This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// js浮点数精确计算。需要在支持static method和class的js环境中运行 | |
// 可以拆分为4个方法(在不支持class和static method)的环境中 | |
// 需要继续完善的是如果x,y中存在几十位的小数那么可能超过安全数字 | |
class Calculate { | |
// x,y是运算数字,n是精度 | |
static add(x, y, n) { | |
const _arg1 = x.toString(); | |
const _arg2 = y.toString(); | |
const arg1Arr = _arg1.split('.'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//get | |
fetch('url').then((res)=>{ | |
if(res.ok){ | |
res.json.then((data)=>{ | |
console.log(data); | |
}) | |
} | |
}).catch((err)=>{ | |
console.log(err); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const arr = { | |
children: [1,2,3] | |
}; | |
arr.childrenGroup = []; | |
arr.children.reduce((r, e, index) => { | |
const lenghtOfChildren = qcSort.children.length; | |
if (index % 2 === 1) { | |
arr.childrenGroup.push([r,e]); | |
} else if (lenghtOfChildren % 2 === 1 && index === lenghtOfChildren - 1) { | |
arr.childrenGroup.push([e]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 将平级数据变为树结构 | |
const arr = [{ | |
id:1, | |
parent: null, | |
},{ | |
id:2, | |
parent: null, | |
},{ | |
id: 3, | |
parent: {id:1} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getVariableType = (v) => { | |
const TYPES = { | |
undefined: 'undefined', | |
number: 'number', | |
boolean: 'boolean', | |
string: 'string', | |
'[object Function]': 'function', | |
'[object RegExp]': 'regexp', | |
'[object Array]': 'array', | |
'[object Date]': 'date', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import PropTypes from 'porp-types'; | |
class Template extends Component { | |
state = {} | |
render(){ | |
return (<div>template</div>); | |
} | |
} |