You are not logged in.
Login
or
Register
.
JsPHP: a JavaScript library providing the PHP API
Home
Register
Demo
Categories
Functions
Contributors
Download
Links
Comments
FAQ
Contact
View
Edit
Benchmark
Revisions
Developers
Dependencies
Talk
Links
array_reduce:
Edit: array_reduce
Function:
array_reduce
View array_reduce
Edit array_reduce
Edit code
Edit tests
Edit benchmark
View latest code
Edit latest code
Benchmark array_reduce
Comment on array_reduce
Comment on the latest code
View revisions
View versions
View contributors
View dependencies
View comments
View links
Download production code
Download development code
View the PHP docs
View phpjs.org
View phpjs.org raw code
Description:
Iteratively reduce the array to a single value via the callback.
Edit function
Code
:
function array_reduce (a_input, callback) { // http://jsphp.co/jsphp/fn/view/array_reduce // + original by: Alfonso Jimenez (http://www.alfonsojimenez.com) // % note 1: Takes a function as an argument, not a function's name // * example 1: array_reduce([1, 2, 3, 4, 5], function (v, w){v += w;return v;}); // * returns 1: 15 var lon = a_input.length; var res = 0, i = 0; var tmp = []; for (i = 0; i < lon; i += 2) { tmp[0] = a_input[i]; if (a_input[(i + 1)]) { tmp[1] = a_input[(i + 1)]; } else { tmp[1] = 0; } res += callback.apply(null, tmp); tmp = []; } return res; }
You have to be logged in to edit functions.
Edit tests
Code
:
You have to be logged in to edit tests.
Edit benchmark
Code
:
You have to be logged in to edit benchmarks.
[
top
]
Comments
There are no comments yet, be the first!
Please
Login
or
Register
to post comments.