خرید بک لینک

Vote count: 0

Sample code with actual results and Browser version (user agent):

> [{count:1},{count:2},{count:3}].reduce(function(prev,curr){console.log(arguments);retu 5;})
[Object, Object, 1, Array[3]]
[5, Object, 2, Array[3]]
5
> navigator.appVersion
"5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36"

Sample code with expected results:

-> [{count:1},{count:2},{count:3}].reduce(function(prev,curr){console.log(arguments);retu 5;})
[0, Object, 0, Array[3]]
[5, Object, 1, Array[3]]
[5, Object, 2, Array[3]]
5

MDN Link: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce Another Link: https://danmartensen.svbtle.com/javascripts-map-reduce-and-filter#reduce_1

asked 2 mins ago

1 Answer

Vote count: 0

Ah, I was missing people's use of the initial value function, to have it start with a number and not skip an iteration, thus not causing the first result to be of a different type than a Number from my example..

Working sample code with small change and actual results:

-> [{count:1},{count:2},{count:3}].reduce(function(prev,curr){console.log(arguments);retu 5;}, 0)
[0, Object, 0, Array[3]]
[5, Object, 1, Array[3]]
[5, Object, 2, Array[3]]

answered 2 mins ago

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 11 مرداد 1395 ساعت: 9:25

صفحه بندی