简体   繁体   English

有人可以解释这里发生的步骤流程吗?

[英]Can someone explain the flow of steps that are happening here?

I'm trying to figure out is each item going through reduce as the map runs, or is the map method running completely, and then after it returns the array, the reduce method is being applied to the array from the map?我试图弄清楚每个项目是否在 map 运行时通过 reduce,或者 map 方法是否完全运行,然后在它返回数组后,reduce 方法正在从 Z1D78DC8ED51214E518B5114FEZ2 应用于数组?

 const lineItems = [
{ description: 'Eggs (Dozen)', quantity: 1, price: 3, total: 3 },
{ description: 'Cheese', quantity: 0.5, price: 5, total: 2.5 },
{ description: 'Butter', quantity: 2, price: 6, total: 12 }
];

let store = lineItems.map(item => item.quantity).reduce(sumReducer, 0);

function sumReducer(sum, val) {
  return sum += val;
}

console.log(store);

All regular - non generator - functions in javascript have run-to-completion semantics. javascript 中的所有常规 - 非生成器 - 函数都具有运行到完成语义。 This means that when they are called, the execute until they return without interruption.这意味着当它们被调用时,执行直到它们返回而不会中断。

In this case the map() function executes and returns an array, then the reduce() function executes.在这种情况下, map() function 执行并返回一个数组,然后reduce() function 执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有人请解释一下这里发生了什么 - Someone pls explain me whats happening here res.redirect() 没有将我重定向到任何页面,没有错误,有人可以解释这里发生了什么吗? - res.redirect() is not redirecting me to any page ,there are no errors ,can someone explain whats happening here? 有人可以解释代码的执行步骤吗? - Can someone explain the steps of execution of code? 有人可以在这里解释“push”是怎么回事吗? - Can someone explain what is going on with `push` here? Anjgularjs中的$ http:有人可以解释这个流程 - $http in Anjgularjs: Can someone explain the flow 有人可以解释一下这个例子中的功能流程吗? - Can someone explain me the flow of functions in this example? 有人可以解释一下此JavaScript代码中发生了什么吗? - can someone please explain what is happening in this javascript code? 有人可以向我解释在这里如何调用for-in循环3次? - Can someone explain to me how the for-in loop is called 3 times here? 有人可以向我解释一下循环是如何在这里工作的吗? - Can someone explain to me how the loop works here? 精通 Javascript 的人可以简单地向我解释这里发生了什么 - Can someone fluent in Javascript explain to me whats going on here SIMPLY
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM