From 000a70a4a16a9726c86f6c595e41c817798788a6 Mon Sep 17 00:00:00 2001 From: YangJ0605 <1442122744@qq.com> Date: Fri, 12 Jun 2020 16:58:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E4=B8=80=E4=BA=9B=E6=95=B0?= =?UTF-8?q?=E7=BB=84=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...60\347\273\204\345\216\273\351\207\215.js" | 2 +- .../index.html" | 1 + ...71\346\263\225\345\256\236\347\216\260.js" | 64 ++++++++++++++++++- 3 files changed, 64 insertions(+), 3 deletions(-) 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 1b37857..4718fb2 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,4 @@ function unique(array) { //es6最įŽ€å• -let unique = (a) => [...new Set(a)] \ No newline at end of file +let unique = (a) => [...new Set(a)] diff --git "a/\345\244\232\346\226\207\344\273\266\344\270\212\344\274\240\346\265\213\350\257\225/index.html" "b/\345\244\232\346\226\207\344\273\266\344\270\212\344\274\240\346\265\213\350\257\225/index.html" index e8c9667..035c922 100644 --- "a/\345\244\232\346\226\207\344\273\266\344\270\212\344\274\240\346\265\213\350\257\225/index.html" +++ "b/\345\244\232\346\226\207\344\273\266\344\270\212\344\274\240\346\265\213\350\257\225/index.html" @@ -12,6 +12,7 @@ var chunkSize=2*1024*1024 var file = document.getElementById('file'), btn = document.getElementById('btn') var formData = new FormData() + var chunks=[] btn.addEventListener('click', () => { var fileItem = file.files[0] var blob = fileItem.slice(0, chunkSize) 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 e807c83..4b66e2d 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" @@ -1,4 +1,14 @@ -Array.prototype.push = function() { +Array.prototype.forEach = function (cb, context = undefined) { + let arr = this.slice() + let len = arr.length + for (let i = 0; i < len; i++) { + if (i in arr) { + cb.call(context, arr[i], i, arr) + } + } +} + +Array.prototype.push = function () { for(let i = 0; i< arguments.length; i++) { this[this.length] = arguments[i] } @@ -25,4 +35,54 @@ Array.prototype.shift = function() { return value } -Array.prototype.unshift = \ No newline at end of file +Array.prototype.map = function (cb, context = undefined) { + let arr = this.slice() + let len = arr.length + let res = [] + for (let i = 0; i < len; i++) { + res[i] = cb.call(context, arr[i], i, arr) + } + return res +} + + +Array.prototype.myReduce = function (cb, initData) { + let arr = this, len = arr.length + let res = initData || arr[0] + let startIndex = initData ? 0 : 1 + for (let i = startIndex; i < len; i++) { + res = cb(res, arr[i], i, arr) + } + return res +} + +Array.prototype.mapByReduce = function (cb, context = null) { + return arr.reduce((pre, curr, index, arr) => { + let res = cb.call(context, curr, index, arr) + return [...pre, res] + },[]) +} + +Array.prototype.filter = function (cb, context=undefined) { + let arr = this.slice() + let len = arr.length + let res = [], newIndex=0 + for (let i = 0; i < len; i++) { + let flag = cb.call(context, arr[i], i, arr) + if (flag) { + console.log(i, flag) + res[newIndex++] = arr[i] + } + } + return res +} + + +Array.prototype.find = function (cb, context) { + let arr = this.slice() + let len = arr.length + for (let i = 0; i < len; i++) { + let res = cb.call(context, arr[i], i, arr) + if(res) return arr[i] + } +} \ No newline at end of file