We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
如题
The text was updated successfully, but these errors were encountered:
Array.prototype._reduce = function (exc, initial = 0) { let result = initial; this.forEach((item) => { result = exc(result, item); }); return result; }
Sorry, something went wrong.
Array.prototype._reduce = function (fn, prev) { if (typeof fn !== 'function') return for (let i = 0; i < this.length; i++) { // 如果不传递prev,那么第一次调用时传递的初始参数就默认为数组的第一个元素,累加元素为数组索引为1处的元素 if (prev === undefined) { prev = fn(this[i], this[i + 1], i + 1, this) // 此时i为1,但是下一次要从索引为2处开始加,所以这里i++ i++ } else { // 如果传递了初始参数,那么传递对应参数即可 prev = fn(prev, this[i], i, this) } } // 最后返回prev,prev是一个元素,但不限类型,可能为数组,对象,数字等 return prev }
No branches or pull requests
如题
The text was updated successfully, but these errors were encountered: