View: array_product

Function:
Description: Returns the product of the array entries.
Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function array_product (input) {
    // http://jsphp.co/jsphp/fn/view/array_product
    // +   original by: Waldo Malqui Silva
    // *     example 1: array_product([ 2, 4, 6, 8 ]);
    // *     returns 1: 384
    var idx = 0,
        product = 1,
        il = 0;

    if (Object.prototype.toString.call(input) !== '[object Array]') {
        return null;
    }

    il = input.length;
    while (idx < il) {
        product *= (!isNaN(input[idx]) ? input[idx] : 0);
        idx++;
    }
    return product;
}
Comment on array_product version 28
Tests
Benchmark
[top]

Comments

There are no comments yet, be the first!

Please Login or Register to post comments.