Skip to content

Instantly share code, notes, and snippets.

View Ai01's full-sized avatar
🎯
Focusing

Ai01

🎯
Focusing
View GitHub Profile
@Ai01
Ai01 / jsNumberCal
Last active August 2, 2017 10:35
js浮点数计算
// 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('.');
@Ai01
Ai01 / fetchApi
Last active August 8, 2017 15:09
fetchApi
//get
fetch('url').then((res)=>{
if(res.ok){
res.json.then((data)=>{
console.log(data);
})
}
}).catch((err)=>{
console.log(err);
})
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]);
@Ai01
Ai01 / Unflatten
Created September 6, 2017 10:25
将平级数据变为树结构
// 将平级数据变为树结构
const arr = [{
id:1,
parent: null,
},{
id:2,
parent: null,
},{
id: 3,
parent: {id:1}
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',
@Ai01
Ai01 / reactComponentTemplate
Last active October 29, 2018 07:41
react component template
import React, { Component } from 'react';
import PropTypes from 'porp-types';
class Template extends Component {
state = {}
render(){
return (<div>template</div>);
}
}
@Ai01
Ai01 / 2.markdown
Created February 8, 2020 07:44
拖拽实现2
@Ai01
Ai01 / .markdown
Created February 8, 2020 09:07
拖拽放置
@Ai01
Ai01 / .markdown
Created February 8, 2020 09:08
拖拽实现