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 event1 = 1; | |
const event2 = 2; | |
function trace(event, keypress = () => []) { | |
return function trace() { | |
return [...keypress(), event]; | |
} | |
} | |
let keypress = trace(event1); |
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
function throttle(fn, delay, cxt) { | |
var start; | |
var timer = null; | |
cxt = cxt || this; | |
delay = delay || 100; | |
return function() { | |
var current = Date.now(); | |
clearTimeout(timer); | |
if (!start) { | |
start = current; |
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
function compose(fn) { | |
var fn = [].slice.call(arguments); | |
return function(value) { | |
while(fn.length > 0) { | |
value = fn.pop()(value); | |
} | |
return value; | |
} | |
} |
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
function compose(fn) { | |
var fnArray = [].slice.call(arguments); | |
return function(value) { | |
return fnArray.reverse().reduce(function(result, fn) { | |
return fn(result) | |
}, value); | |
}; | |
} |
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
function compose(fn) { | |
var fnArray = [].slice.call(arguments); | |
return fnArray.reverse().reduce(function(fgr, fn) { | |
// 因为传入的是一个函数,最终输出一个函数 fgr =====> function | |
return function() { | |
var args = [].slice.call(arguments); | |
return fn(fgr.apply(null, args)); | |
}; | |
}); | |
} |
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
function compose(fn) { | |
// 传入的函数大于等于2 | |
var fnArray = [].slice.call(arguments).reverse(); | |
var fn1 = fnArray[0]; | |
var fn2 = fnArray[1]; | |
if (fnArray.length > 2) { | |
var restArray = fnArray.slice(2); |
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
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); | |
} | |
})([]); |
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 double = x => x * x; | |
[1, 2, 3].map(double); | |
[1, 2, 3].reduce((result, item) => ( | |
result.push(double(item)), result | |
), []) |
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
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; |
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
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) { |
OlderNewer