diff --git a/canvas/1.js b/canvas/1.js new file mode 100644 index 0000000..992b37e --- /dev/null +++ b/canvas/1.js @@ -0,0 +1,5 @@ +class Regcode { + constructor() { + + } +} \ No newline at end of file diff --git a/curry.js b/curry.js new file mode 100644 index 0000000..8d12e45 --- /dev/null +++ b/curry.js @@ -0,0 +1,23 @@ +function curry(fn, length) { + length = length || fn.length + return function(...args) { + if (args.length < length) { + return curry(sub_curry(fn, ...args),length - args.length) + } else { + return fn.call(this, ...args) + } + } +} + +function sub_curry(fn, ...args) { + return function (...newArgs) { + return fn.apply(this, [...args, ...newArgs]) + } +} + +var fn = curry(function (a, b, c) { + return [a,b,c] +}) +console.log(fn(1,2, 44)) +console.log(fn(1, 2)(44)) +console.log(fn(1)(2)(44)) \ No newline at end of file diff --git "a/\344\270\223\351\242\230\347\263\273\345\210\227/\346\225\260\347\273\204\345\216\273\351\207\215.js" "b/\344\270\223\351\242\230\347\263\273\345\210\227/\346\225\260\347\273\204\345\216\273\351\207\215.js" index 4718fb2..13df861 100644 --- "a/\344\270\223\351\242\230\347\263\273\345\210\227/\346\225\260\347\273\204\345\216\273\351\207\215.js" +++ "b/\344\270\223\351\242\230\347\263\273\345\210\227/\346\225\260\347\273\204\345\216\273\351\207\215.js" @@ -64,4 +64,50 @@ function unique(array) { //es6最įŽ€å• -let unique = (a) => [...new Set(a)] +// let unique = (a) => [...new Set(a)] +var arr = [1, 1, '1', '1'] + +function unique(arr) { + var res = [] + for (var i = 0; i < arr.length; i++) { + // if (!(arr[i] in temp)) { + // temp[arr[i]] = arr[i] + // res[j++] = arr[i] + // } + // for (var j = 0; j < res.length; j++) { + // if (arr[i] === res[j]) { + // break + // } + // } + // if (j === res.length) { + // res.push(arr[i]) + // } + if (res.indexOf(arr[i]) === -1) { + res.push(arr[i]) + } + } + return res +} + +function unique2(arr) { + var res = [], len = arr.length + var sortedArr = arr.concat().sort() + var seen + for (var i = 0; i < len; i++) { + if (!i || seen !== sortedArr[i]) { + res.push(sortedArr[i]) + } + seen = sortedArr[i] + } + return res +} + +function unique3(arr) { + var _set = {}, res = [] + for (let i = 0; i < arr.length; i++) { + let key = typeof arr[i] + arr[i] + _set[key] || (_set[key] = true, res.push(arr[i])) + } + return res +} +console.log(unique3(arr)) diff --git "a/\344\270\223\351\242\230\347\263\273\345\210\227/\346\225\260\347\273\204\346\211\201\345\271\263\345\214\226.html" "b/\344\270\223\351\242\230\347\263\273\345\210\227/\346\225\260\347\273\204\346\211\201\345\271\263\345\214\226.html" index b0fe272..258870d 100644 --- "a/\344\270\223\351\242\230\347\263\273\345\210\227/\346\225\260\347\273\204\346\211\201\345\271\263\345\214\226.html" +++ "b/\344\270\223\351\242\230\347\263\273\345\210\227/\346\225\260\347\273\204\346\211\201\345\271\263\345\214\226.html" @@ -11,13 +11,13 @@ var arr = [1, [2, [3, 4]]]; - function xx(arr) { + function flat(arr) { return arr.reduce((pre,next) => { return pre.concat(Array.isArray(next)? xx(next) : next) },[]) } - console.log(xx(arr)) + console.log(falt(arr)) \ No newline at end of file diff --git "a/\346\225\260\347\273\204\344\270\200\344\272\233\345\270\270\347\224\250\347\232\204\346\226\271\346\263\225\345\256\236\347\216\260.js" "b/\346\225\260\347\273\204\344\270\200\344\272\233\345\270\270\347\224\250\347\232\204\346\226\271\346\263\225\345\256\236\347\216\260.js" index 4b66e2d..74704c3 100644 --- "a/\346\225\260\347\273\204\344\270\200\344\272\233\345\270\270\347\224\250\347\232\204\346\226\271\346\263\225\345\256\236\347\216\260.js" +++ "b/\346\225\260\347\273\204\344\270\200\344\272\233\345\270\270\347\224\250\347\232\204\346\226\271\346\263\225\345\256\236\347\216\260.js" @@ -85,4 +85,5 @@ Array.prototype.find = function (cb, context) { let res = cb.call(context, arr[i], i, arr) if(res) return arr[i] } -} \ No newline at end of file +} +