Sometimes we need to turn arrays into new values in ways that can't be done purely by passing an accumulator along with no knowledge about its context. Learn how to reduce an array of numbers into its mathematical mean in a single reduce step by using the optional index and array reducer arguments.

function reducer(accumulator, value, index, array) {
var intermediaryValue = accumulator + value; if (index === array.length - 1) {
return intermediaryValue / array.length;
} return intermediaryValue;
} var data = [1, 2, 3, 3, 4, 5, 3, 1];
var mean = data.reduce(reducer, 0); console.log(mean);

[Javascript] Advanced Reduce: Additional Reducer Arguments的更多相关文章

  1. [Javascript] Advanced Reduce: Flatten, Flatmap and ReduceRight

    Learn a few advanced reduction patterns: flatten allows you to merge a set of arrays into a single a ...

  2. [Javascript] Advanced Reduce: Common Mistakes

    Take away: Always check you ruturn the accumulator Always pass in the inital value var data = [" ...

  3. [Javascript] Advanced Reduce: Composing Functions with Reduce

    Learn how to use array reduction to create functional pipelines by composing arrays of functions. co ...

  4. JavaScript中reduce()方法

    原文  http://aotu.io/notes/2016/04/15/2016-04-14-js-reduce/   JavaScript中reduce()方法不完全指南 reduce() 方法接收 ...

  5. javascript 函数详解2 -- arguments

    今天我们接着上篇文章来继续javascript函数这个主题.今天要讲的是函数对像中一个很重要的属性--arguments. 相关阅读: javascript 函数详解1 -- 概述 javascrip ...

  6. [Javascript] Advanced Console Log Arguments

    Get more mileage from your console output by going beyond mere string logging - log entire introspec ...

  7. javascript的Function 和其 Arguments

    http://shengren-wang.iteye.com/blog/1343256 javascript的Function属性:1.Arguments对象2.caller 对调用单前函数的Func ...

  8. 随笔:JavaScript函数中的对象----arguments

    关于arguments 调用函数时,如果需要传参,其实参数就是一个数组,在函数体的内置对象arguments可以访问这个数组,如: arguments[0]:第一个参数 arguments[1]:第二 ...

  9. JavaScript 没有函数重载&Arguments对象

    对于学过Java的人来说.函数重载并非一个陌生的概念,可是javaScript中有函数重载么...接下来我们就进行測试 <script type="text/javascript&qu ...

随机推荐

  1. iOS 不同类之间的传值

    iOS是面向对象开发的,有很多不同的类,很多时候会遇到类与类之间的"交流"需求,比如通知.传递数值等等,(通知可以用nsnotificationcenter来做, 以后总结)下面主 ...

  2. hello,boke

    我一名学习软件工程金融服务工程的学生,简单来说就是学习计算机类的,对于自己的介绍,从平时生活中来说吧,我一直处于一种很中规中矩的生活状态里,平时玩玩手机.追追剧.和室友一起去图书馆自习,考前拼命复习两 ...

  3. (转)QT常用快捷键

    F1        查看帮助F2        跳转到函数定义(和Ctrl+鼠标左键一样的效果)Shift+F2    声明和定义之间切换F4        头文件和源文件之间切换Ctrl+1     ...

  4. 理解O/R Mapping

    本文的目的是以最精炼的语言,理解什么是O/R Mapping,为什么要O/R Mapping,和如何进行O/R Mapping. 什么是O/R Mapping? 广义上,ORM指的是面向对象的对象模型 ...

  5. android异常之emulator-arm.exe已停止工作

    我遇到的这个问题通过降低了AVD的分辨率后解决了,估计是电脑的显卡不行.

  6. linux修改环境变量

    /etc/profile 系统全局环境变量设定,所有用户共享,修改后,需要重启系统才能生效 ~/.bash_profile,~/.bashrc 用户目录下的私有环境变量设定,常用来个性化定制功能,修改 ...

  7. MVC中的Ajax(AjaxHelper)

    authour: chenboyi updatetime: 2015-04-30 20:47:49 friendly link:   目录 1,思维导图 2,ActionLink() 3,BeginF ...

  8. Xcode7调试-b

    Xcode7中苹果为我们增加了两个重要的debug相关功能.了解之后觉得非常实用,介绍给大家. 1.Address Sanitizer: 妈妈再也不用担心 EXC_BAD_ACCESS? EXC_BA ...

  9. What qualities characterize a great PhD student

    省理工计算机教授David Karger接触了许多世界上最杰出的博士生,近日总结出了优秀博士通常具备的五点品质:0 过人的智力 1 好奇心 2 创造力 3 纪律性与生产力 4 与观众沟通 5 与伙伴沟 ...

  10. zoj 3785 What day is that day?

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5272 打表找规律. #include <cstdio> #incl ...