Skip to content

Instantly share code, notes, and snippets.

View LeeeeeeM's full-sized avatar
🎯
专心研究webpack的细节。

EMpersonal LeeeeeeM

🎯
专心研究webpack的细节。
View GitHub Profile
@LeeeeeeM
LeeeeeeM / th_de.js
Last active March 11, 2018 11:57
节流函数 与 防抖函数
function throttle(fn, delay, context) {
var timer;
var context = context || this;
var first = true;
return function() {
if (first) {
fn.apply(context, [].slice.apply(arguments));
first = false;
}
if (timer) {
@LeeeeeeM
LeeeeeeM / throttle.js
Last active March 21, 2018 02:30
节流函数
function throttle(fn, timeout, mustRunTime, context) {
var last;
var timer;
return function() {
current = Date.now();
if (!last) {
last = current;
}
clearTimeout(timer);
if (current - last >= mustRunTime) {
@LeeeeeeM
LeeeeeeM / insertSort.js
Created March 10, 2018 04:13
插入排序
function insertSort(array) {
var length = array.length;
var j,temp;
for(var i = 0; i < length; i++) {
j = i;
temp = array[i];
while(j > 0 && array[j - 1] > temp) {
array[j] = array[j - 1];
j--;
}
@LeeeeeeM
LeeeeeeM / selectionSort.js
Created March 10, 2018 03:55
选择排序
function selectionSort(array) {
var length = array.length;
for (var i = 0; i < length - 1; i++) {
var minIndex = i;
for(var j = i; j < array.length; j++) {
if (array[minIndex] > array[j]) {
minIndex = j;
}
}
if (minIndex !== i) {
@LeeeeeeM
LeeeeeeM / bubbleSort.js
Last active March 10, 2018 07:19
冒泡
function bubbleSort(array) {
var length = array.length;
for (var i = 0; i < length - 1; i++) {
for (var j = 0; j< length - 1 -i; j++) {
if (array[j] > array[j + 1]) {
swap(array, j, j+1);
}
}
}
@LeeeeeeM
LeeeeeeM / Class.js
Created March 10, 2018 02:57
javascript extends
var Class = (function () {
initial = false;
// var _mix = function(target, source) {
// for (var k in source) {
// if (!target.hasOwnProperty(k)) {
// target[k] = source[k];
// }
// }
// return target;
@LeeeeeeM
LeeeeeeM / reduceAsMap.js
Created March 8, 2018 05:39
reduceAsMap
const double = x => x * x;
[1, 2, 3].map(double);
[1, 2, 3].reduce((result, item) => (
result.push(double(item)), result
), [])
@LeeeeeeM
LeeeeeeM / reqPraGetSeq.js
Last active August 2, 2018 02:11
request同时加载但是依次返回结果
var timeout = (time, value) => {
console.log('step into promise', time, value);
return new Promise(resolve => {
setTimeout(resolve, time, value);
});
};
var queue = [2, 3, 5, 99, 1];
var dosth = value => {
@LeeeeeeM
LeeeeeeM / compose.js
Last active December 13, 2019 08:52
compose 函数组合
// 原始方法
function compose(...fns) {
return function composed(result) {
var list = fns.slice();
while(list.length > 0) {
result = list.pop()(result);
}
return result;
}
}
@LeeeeeeM
LeeeeeeM / curry.js
Created February 26, 2018 06:57
柯里化
function curry(fn, arity = fn.length) {
return (function nextCurried(prevArgs) {
return function curried(...nextArgs) {
var args = prevArgs.concat(nextArgs);
if (args.length >= arity) {
return fn(...args);
}
return nextCurried(args);
}
})([]);